Skip to content

Commit 671ef47

Browse files
refactor(api): move acceptance test from /lib to /src/team
1 parent 1152646 commit 671ef47

File tree

2 files changed

+84
-99
lines changed

2 files changed

+84
-99
lines changed

api/tests/acceptance/application/memberships/membership-controller_test.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

api/tests/team/acceptance/application/membership/membership.route.test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,88 @@ describe('Acceptance | Team | Application | Route | membership', function () {
315315
});
316316
});
317317
});
318+
319+
describe('POST /api/memberships/{id}/disable', function () {
320+
let options;
321+
let membershipId;
322+
let organizationId;
323+
324+
beforeEach(async function () {
325+
organizationId = databaseBuilder.factory.buildOrganization().id;
326+
const userId = databaseBuilder.factory.buildUser().id;
327+
membershipId = databaseBuilder.factory.buildMembership({ organizationId, userId }).id;
328+
const organizationAdminUserId = databaseBuilder.factory.buildUser().id;
329+
databaseBuilder.factory.buildMembership({
330+
userId: organizationAdminUserId,
331+
organizationId,
332+
organizationRole: Membership.roles.ADMIN,
333+
});
334+
335+
await databaseBuilder.commit();
336+
337+
options = {
338+
method: 'POST',
339+
url: `/api/memberships/${membershipId}/disable`,
340+
payload: {
341+
data: {
342+
id: membershipId.toString(),
343+
type: 'memberships',
344+
relationships: {
345+
user: {
346+
data: {
347+
type: 'users',
348+
id: userId,
349+
},
350+
},
351+
organization: {
352+
data: {
353+
type: 'organizations',
354+
id: organizationId,
355+
},
356+
},
357+
},
358+
},
359+
},
360+
headers: generateAuthenticatedUserRequestHeaders({ userId: organizationAdminUserId }),
361+
};
362+
});
363+
364+
context('Success cases', function () {
365+
context('When user is admin of the organization', function () {
366+
it('should return a 204', async function () {
367+
// when
368+
const response = await server.inject(options);
369+
370+
// then
371+
expect(response.statusCode).to.equal(204);
372+
});
373+
});
374+
});
375+
376+
context('Error cases', function () {
377+
it('should respond with a 403 if user does not have the role Admin in organization', async function () {
378+
// given
379+
const notOrganizationAdminUserId = databaseBuilder.factory.buildUser().id;
380+
options.headers = generateAuthenticatedUserRequestHeaders({ userId: notOrganizationAdminUserId });
381+
382+
// when
383+
const response = await server.inject(options);
384+
385+
// then
386+
expect(response.statusCode).to.equal(403);
387+
});
388+
389+
it('should respond with a 400 if membership does not exist', async function () {
390+
// given
391+
const unknownMembershipId = 9999;
392+
options.url = `/api/memberships/${unknownMembershipId}/disable`;
393+
394+
// when
395+
const response = await server.inject(options);
396+
397+
// then
398+
expect(response.statusCode).to.equal(400);
399+
});
400+
});
401+
});
318402
});

0 commit comments

Comments
 (0)