Skip to content

Commit

Permalink
tests: Support concurrent runs of the last org administrator removal …
Browse files Browse the repository at this point in the history
…test

Change-type: patch
  • Loading branch information
thgreasi committed Nov 13, 2024
1 parent 9354fba commit 2c41c28
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/integration/models/organization-membership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
givenInitialOrganization,
givenLoggedInUser,
organizationRetrievalFields,
TEST_ORGANIZATION_NAME,
} from '../setup';
import type * as BalenaSdk from '../../..';
import { assertDeepMatchAndLength, timeSuite } from '../../util';
Expand Down Expand Up @@ -296,19 +297,28 @@ describe('Organization Membership Model', function () {
});
});

describe('given an administrator organization membership [contained scenario]', function () {
describe('given an organization with an administrator organization membership [contained scenario]', function () {
const testOrg1Name = `${TEST_ORGANIZATION_NAME}_org_member_tests_${Date.now()}`;
let testOrg: BalenaSdk.PinePostResult<BalenaSdk.Organization> | undefined;
let membership:
| BalenaSdk.OrganizationMembership
| BalenaSdk.PinePostResult<BalenaSdk.OrganizationMembership>
| undefined;
before(async function () {
testOrg = await balena.models.organization.create({
name: testOrg1Name,
});
membership = await balena.models.organization.membership.create({
organization: this.organization.id,
organization: testOrg.id,
username: credentials.member.username,
roleName: 'administrator',
});
});

after(async function () {
await balena.models.organization.remove(testOrg!.id);
});

describe('balena.models.organization.membership.changeRole()', function () {
it(`should not be able to change an organization membership to an unknown role`, async function () {
const promise = balena.models.organization.membership.changeRole(
Expand Down Expand Up @@ -355,7 +365,7 @@ describe('Organization Membership Model', function () {
);
expect(membership).to.have.nested.property(
'is_member_of__organization[0].id',
this.organization.id,
testOrg!.id,
);
expect(membership).to.have.nested.property(
'organization_membership_role[0].name',
Expand Down Expand Up @@ -386,7 +396,7 @@ describe('Organization Membership Model', function () {
it(`should not be able to remove the last membership of the organization`, async function () {
const [lastAdminMembership] =
await balena.models.organization.membership.getAllByOrganization(
this.organization.id,
testOrg!.id,
{
$select: 'id',
$filter: { user: this.userId },
Expand Down

0 comments on commit 2c41c28

Please sign in to comment.