-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop deprecated method
organization-membership.create
Change-type: major
- Loading branch information
1 parent
5c2d34a
commit cc753fb
Showing
4 changed files
with
89 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { expect } from 'chai'; | ||
import parallel from 'mocha.parallel'; | ||
import { balena, givenInitialOrganization, givenLoggedInUser } from '../setup'; | ||
import { timeSuite } from '../../util'; | ||
import { assertDeepMatchAndLength } from '../../util'; | ||
import { | ||
balena, | ||
givenInitialOrganization, | ||
givenLoggedInUser, | ||
credentials, | ||
organizationRetrievalFields, | ||
} from '../setup'; | ||
import { timeSuite, assertDeepMatchAndLength } from '../../util'; | ||
import type * as BalenaSdk from '../../..'; | ||
const TEST_EMAIL = '[email protected]'; | ||
const TEST_MESSAGE = 'Hey!, Join my org on balenaCloud'; | ||
const TEST_ROLE = 'member'; | ||
|
@@ -119,6 +125,84 @@ describe('Organization Invite Model', function () { | |
}); | ||
}); | ||
}); | ||
|
||
parallel('[read operations]', function () { | ||
const randomOrdInfo = { | ||
id: Math.floor(Date.now() / 1000), | ||
handle: `random_sdk_test_org_handle_${Math.floor(Date.now() / 1000)}`, | ||
}; | ||
|
||
organizationRetrievalFields.forEach((field) => { | ||
it(`should not be able to invite a new member when using an not existing organization ${field}`, async function () { | ||
const promise = balena.models.organization.invite.create( | ||
randomOrdInfo[field], | ||
{ | ||
invitee: credentials.member.email, | ||
roleName: 'member', | ||
}, | ||
); | ||
await expect(promise).to.be.rejected.and.eventually.have.property( | ||
'code', | ||
'BalenaOrganizationNotFound', | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('[mutating operations]', function () { | ||
let membership: | ||
| BalenaSdk.PinePostResult<BalenaSdk.OrganizationInvite> | ||
| undefined; | ||
afterEach(async function () { | ||
await balena.models.organization.membership.remove(membership!.id); | ||
}); | ||
organizationRetrievalFields.forEach(function (field) { | ||
it(`should be able to invite a new member to the organization by ${field}`, async function () { | ||
membership = await balena.models.organization.invite.create( | ||
this.organization[field], | ||
{ | ||
invitee: credentials.member.email, | ||
}, | ||
); | ||
|
||
expect(membership) | ||
.to.be.an('object') | ||
.that.has.nested.property('organization_membership_role.__id') | ||
.that.equals(this.orgMemberRole.id); | ||
}); | ||
}); | ||
|
||
it(`should be able to invite a new member to the organization without providing a role`, async function () { | ||
membership = await balena.models.organization.invite.create( | ||
this.organization.id, | ||
{ | ||
invitee: credentials.member.email, | ||
}, | ||
); | ||
|
||
expect(membership) | ||
.to.be.an('object') | ||
.that.has.nested.property('organization_membership_role.__id') | ||
.that.equals(this.orgMemberRole.id); | ||
}); | ||
|
||
(['member', 'administrator'] as const).forEach(function (roleName) { | ||
it(`should be able to invite a new member to the organization with a given role [${roleName}]`, async function () { | ||
membership = await balena.models.organization.invite.create( | ||
this.organization.id, | ||
{ | ||
invitee: credentials.member.email, | ||
roleName, | ||
}, | ||
); | ||
|
||
expect(membership) | ||
.to.be.an('object') | ||
.that.has.nested.property('organization_membership_role.__id') | ||
.that.equals(this.orgRoleMap[roleName].id); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('given a single organization invite [contained scenario]', function () { | ||
|