-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): migrate new certification center member route
- Loading branch information
Showing
9 changed files
with
278 additions
and
236 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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ import { | |
} from '../../../test-helper.js'; | ||
|
||
describe('Acceptance | API | Certification Center', function () { | ||
let server, request; | ||
let server; | ||
|
||
beforeEach(async function () { | ||
server = await createServer(); | ||
|
@@ -197,108 +197,6 @@ describe('Acceptance | API | Certification Center', function () { | |
}); | ||
}); | ||
|
||
describe('POST /api/admin/certification-centers/{certificationCenterId}/certification-center-memberships', function () { | ||
let certificationCenterId; | ||
let email; | ||
|
||
beforeEach(async function () { | ||
email = '[email protected]'; | ||
|
||
certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; | ||
databaseBuilder.factory.buildUser({ email }); | ||
|
||
request = { | ||
headers: generateAuthenticatedUserRequestHeaders(), | ||
method: 'POST', | ||
url: `/api/admin/certification-centers/${certificationCenterId}/certification-center-memberships`, | ||
payload: { email }, | ||
}; | ||
|
||
await databaseBuilder.commit(); | ||
}); | ||
|
||
it('should return 201 HTTP status', async function () { | ||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(201); | ||
}); | ||
|
||
context('when user is not SuperAdmin', function () { | ||
it('should return 403 HTTP status code ', async function () { | ||
// given | ||
request.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(403); | ||
}); | ||
}); | ||
|
||
context('when user is not authenticated', function () { | ||
it('should return 401 HTTP status code', async function () { | ||
// given | ||
request.headers.authorization = 'invalid.access.token'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(401); | ||
}); | ||
}); | ||
|
||
context('when certification center does not exist', function () { | ||
it('should return 404 HTTP status code', async function () { | ||
// given | ||
request.url = '/api/admin/certification-centers/1/certification-center-memberships'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(400); | ||
}); | ||
}); | ||
|
||
context("when user's email does not exist", function () { | ||
it('should return 404 HTTP status code', async function () { | ||
// given | ||
request.payload.email = '[email protected]'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
context('when user is already member of the certification center', function () { | ||
it('should return 412 HTTP status code', async function () { | ||
// given | ||
email = '[email protected]'; | ||
const userId = databaseBuilder.factory.buildUser({ email }).id; | ||
databaseBuilder.factory.buildCertificationCenterMembership({ | ||
certificationCenterId, | ||
userId, | ||
}); | ||
request.payload.email = email; | ||
|
||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(412); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('POST /api/certif/certification-centers/{certificationCenterId}/update-referer', function () { | ||
it('should return 204 HTTP status', async function () { | ||
// given | ||
|
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 |
---|---|---|
|
@@ -250,4 +250,108 @@ describe('Acceptance | Team | Application | Admin | Routes | certification-cente | |
}); | ||
}); | ||
}); | ||
|
||
describe('POST /api/admin/certification-centers/{certificationCenterId}/certification-center-memberships', function () { | ||
let certificationCenterId; | ||
let email; | ||
let request; | ||
|
||
beforeEach(async function () { | ||
email = '[email protected]'; | ||
|
||
certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; | ||
const adminId = databaseBuilder.factory.buildUser.withRole().id; | ||
databaseBuilder.factory.buildUser({ email }); | ||
|
||
request = { | ||
headers: generateAuthenticatedUserRequestHeaders({ userId: adminId }), | ||
method: 'POST', | ||
url: `/api/admin/certification-centers/${certificationCenterId}/certification-center-memberships`, | ||
payload: { email }, | ||
}; | ||
|
||
await databaseBuilder.commit(); | ||
}); | ||
|
||
it('should return 201 HTTP status', async function () { | ||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(201); | ||
}); | ||
|
||
context('when user is not SuperAdmin', function () { | ||
it('should return 403 HTTP status code ', async function () { | ||
// given | ||
request.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(403); | ||
}); | ||
}); | ||
|
||
context('when user is not authenticated', function () { | ||
it('should return 401 HTTP status code', async function () { | ||
// given | ||
request.headers.authorization = 'invalid.access.token'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(401); | ||
}); | ||
}); | ||
|
||
context('when certification center does not exist', function () { | ||
it('should return 404 HTTP status code', async function () { | ||
// given | ||
request.url = '/api/admin/certification-centers/1/certification-center-memberships'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(400); | ||
}); | ||
}); | ||
|
||
context("when user's email does not exist", function () { | ||
it('should return 404 HTTP status code', async function () { | ||
// given | ||
request.payload.email = '[email protected]'; | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
context('when user is already member of the certification center', function () { | ||
it('should return 412 HTTP status code', async function () { | ||
// given | ||
email = '[email protected]'; | ||
const userId = databaseBuilder.factory.buildUser({ email }).id; | ||
databaseBuilder.factory.buildCertificationCenterMembership({ | ||
certificationCenterId, | ||
userId, | ||
}); | ||
request.payload.email = email; | ||
|
||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const response = await server.inject(request); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(412); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.