Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Support concurrent runs of the last org administrator removal test #1490

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/integration/models/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ describe('Application Model', function () {
it('should be rejected if the application slug does not exist', function () {
const promise = balena.models.application.rename(
`${this.initialOrg.handle}/helloworldapp`,
'newAppName',
`${TEST_APPLICATION_NAME_PREFIX}_newAppName`,
);
return expect(promise).to.be.rejectedWith(
`Application not found: ${this.initialOrg.handle}/helloworldapp`,
Expand All @@ -576,17 +576,18 @@ describe('Application Model', function () {
});
applicationRetrievalFields.forEach((prop) => {
it(`should be able to rename an existing application by ${prop}`, async function () {
const newApplicationName = `${TEST_APPLICATION_NAME_PREFIX}_newApplicationName_${prop}`;
await balena.models.application.rename(
this.application[prop],
'newApplicationName_' + prop,
newApplicationName,
);
const app = await balena.models.application.get(
this.application.id,
{
$select: 'app_name',
},
);
expect(app).to.have.property(
'app_name',
'newApplicationName_' + prop,
);
expect(app).to.have.property('app_name', newApplicationName);
});
});
});
Expand Down
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
Loading