-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] 🚚 Déplacement de la route
session-summaries
vers src
- Loading branch information
Showing
15 changed files
with
175 additions
and
134 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
22 changes: 22 additions & 0 deletions
22
...tion/session-management/application/certification-centers-session-summaries-controller.js
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { usecases } from '../domain/usecases/index.js'; | ||
import * as sessionSummarySerializer from '../infrastructure/serializers/session-summary-serializer.js'; | ||
|
||
const findPaginatedSessionSummaries = async function (request) { | ||
const certificationCenterId = request.params.id; | ||
const userId = request.auth.credentials.userId; | ||
const options = request.query; | ||
|
||
const { models: sessionSummaries, meta } = await usecases.findPaginatedCertificationCenterSessionSummaries({ | ||
userId, | ||
certificationCenterId, | ||
page: options.page, | ||
}); | ||
|
||
return sessionSummarySerializer.serialize(sessionSummaries, meta); | ||
}; | ||
|
||
const certificationCenterController = { | ||
findPaginatedSessionSummaries, | ||
}; | ||
|
||
export { certificationCenterController }; |
35 changes: 35 additions & 0 deletions
35
...ification/session-management/application/certification-centers-session-summaries-route.js
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Joi from 'joi'; | ||
|
||
import { certificationCenterController } from '../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js'; | ||
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; | ||
|
||
const register = async function (server) { | ||
server.route([ | ||
{ | ||
method: 'GET', | ||
path: '/api/certification-centers/{id}/session-summaries', | ||
config: { | ||
validate: { | ||
params: Joi.object({ | ||
id: identifiersType.certificationCenterId, | ||
}), | ||
query: Joi.object({ | ||
page: Joi.object({ | ||
number: Joi.number().integer().empty('').allow(null).optional(), | ||
size: Joi.number().integer().empty('').allow(null).optional(), | ||
}).default({}), | ||
}), | ||
}, | ||
handler: certificationCenterController.findPaginatedSessionSummaries, | ||
tags: ['api', 'certification-center'], | ||
notes: [ | ||
'- **Cette route est restreinte aux utilisateurs authentifiés**\n', | ||
'- Elle retourne les sessions rattachées au centre de certification.', | ||
], | ||
}, | ||
}, | ||
]); | ||
}; | ||
|
||
const name = 'session-summaries-api'; | ||
export { name, register }; |
2 changes: 1 addition & 1 deletion
2
...certification-center-session-summaries.js → ...certification-center-session-summaries.js
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
File renamed without changes.
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
78 changes: 78 additions & 0 deletions
78
...on-management/unit/application/certification-centers-session-summaries-controller.test.js
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { certificationCenterController } from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js'; | ||
import { usecases } from '../../../../../src/certification/session-management/domain/usecases/index.js'; | ||
import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Controller | certifications-center-controller', function () { | ||
describe('#findPaginatedSessionSummaries', function () { | ||
beforeEach(function () { | ||
sinon.stub(usecases, 'findPaginatedCertificationCenterSessionSummaries'); | ||
}); | ||
|
||
it('should return a list of JSON API session summaries with pagination information', async function () { | ||
// given | ||
const request = { | ||
params: { id: 456 }, | ||
auth: { credentials: { userId: 123 } }, | ||
query: { | ||
page: { | ||
number: 1, | ||
size: 10, | ||
}, | ||
}, | ||
}; | ||
const sessionSummary = domainBuilder.buildSessionSummary.created({ | ||
id: 1, | ||
address: 'ici', | ||
room: 'la-bas', | ||
date: '2020-01-01', | ||
time: '16:00', | ||
examiner: 'Moi', | ||
enrolledCandidatesCount: 5, | ||
effectiveCandidatesCount: 4, | ||
}); | ||
usecases.findPaginatedCertificationCenterSessionSummaries | ||
.withArgs({ | ||
userId: 123, | ||
certificationCenterId: 456, | ||
page: { number: 1, size: 10 }, | ||
}) | ||
.resolves({ | ||
models: [sessionSummary], | ||
meta: { page: 1, pageSize: 10, itemsCount: 1, pagesCount: 1, hasSessions: true }, | ||
}); | ||
|
||
// when | ||
const serializedSessionSummaries = await certificationCenterController.findPaginatedSessionSummaries( | ||
request, | ||
hFake, | ||
); | ||
|
||
// then | ||
expect(serializedSessionSummaries).to.deep.equal({ | ||
data: [ | ||
{ | ||
id: '1', | ||
type: 'session-summaries', | ||
attributes: { | ||
address: 'ici', | ||
room: 'la-bas', | ||
date: '2020-01-01', | ||
time: '16:00', | ||
examiner: 'Moi', | ||
'effective-candidates-count': 4, | ||
'enrolled-candidates-count': 5, | ||
status: 'created', | ||
}, | ||
}, | ||
], | ||
meta: { | ||
hasSessions: true, | ||
itemsCount: 1, | ||
page: 1, | ||
pageSize: 10, | ||
pagesCount: 1, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
...session-management/unit/application/certification-centers-session-summaries-route.test.js
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { certificationCenterController } from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js'; | ||
import * as moduleUnderTest from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-route.js'; | ||
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Certification | Session-management | Unit | Application | Routes | session-summaries', function () { | ||
describe('GET /api/certification-centers/{certificationCenterId}/session-summaries', function () { | ||
it('should return 200', async function () { | ||
// given | ||
sinon.stub(certificationCenterController, 'findPaginatedSessionSummaries').returns('ok'); | ||
const httpTestServer = new HttpTestServer(); | ||
await httpTestServer.register(moduleUnderTest); | ||
|
||
// when | ||
const response = await httpTestServer.request('GET', '/api/certification-centers/123/session-summaries'); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(200); | ||
sinon.assert.calledOnce(certificationCenterController.findPaginatedSessionSummaries); | ||
}); | ||
}); | ||
}); |
6 changes: 3 additions & 3 deletions
6
...fication-center-session-summaries_test.js → ...fication-center-session-summaries_test.js
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
4 changes: 2 additions & 2 deletions
4
...sonapi/session-summary-serializer_test.js → ...lizers/session-summary-serializer_test.js
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
Oops, something went wrong.