Skip to content

Commit 570380d

Browse files
clemlatzer-lim
andcommitted
feat(api): add passage event route
Co-authored-by: Eric Lim <eric.lim@pix.fr>
1 parent 06b9083 commit 570380d

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

Diff for: api/src/devcomp/application/passage-events/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { handlerWithDependencies } from '../../infrastructure/utils/handlerWithDependencies.js';
2+
import { passageEventsController } from './passage-events-controller.js';
3+
4+
const register = async function (server) {
5+
server.route([
6+
{
7+
method: 'POST',
8+
path: '/api/passage-events',
9+
config: {
10+
auth: false,
11+
handler: handlerWithDependencies(passageEventsController.create),
12+
notes: ['- Permet de créer un évènement utilisateur pour un passage'],
13+
tags: ['api', 'passages', 'modules', 'events'],
14+
},
15+
},
16+
]);
17+
};
18+
19+
const name = 'passage-events-api';
20+
export { name, register };

Diff for: api/src/devcomp/routes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as modulesRoutes from './application/modules/index.js';
2+
import * as passageEvents from './application/passage-events/index.js';
23
import * as passages from './application/passages/index.js';
34
import * as trainings from './application/trainings/index.js';
45
import * as evaluationTutorials from './application/tutorial-evaluations/index.js';
56
import * as userTutorials from './application/user-tutorials/index.js';
67

7-
const devcompRoutes = [modulesRoutes, passages, trainings, userTutorials, evaluationTutorials];
8+
const devcompRoutes = [modulesRoutes, passages, passageEvents, trainings, userTutorials, evaluationTutorials];
89

910
export { devcompRoutes };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createServer, databaseBuilder, expect, knex } from '../../../../test-helper.js';
2+
3+
describe('Acceptance | Controller | passage-events-controller', function () {
4+
let server;
5+
6+
beforeEach(async function () {
7+
server = await createServer();
8+
});
9+
10+
describe('POST /api/passages-events', function () {
11+
it('should create a new passage event and response with a 201', async function () {
12+
// given
13+
const passage = databaseBuilder.factory.buildPassage();
14+
await databaseBuilder.commit();
15+
16+
// when
17+
const response = await server.inject({
18+
method: 'POST',
19+
url: '/api/passage-events',
20+
payload: {
21+
data: {
22+
type: 'passage-event-collection',
23+
attributes: {
24+
'passage-events': [
25+
{
26+
type: 'FLASHCARDS_STARTED',
27+
'occurred-at': 1556419320000,
28+
'passage-id': passage.id,
29+
'element-id': '5ad40bc9-8b5c-47ee-b893-f8ab1a1b8095',
30+
},
31+
],
32+
},
33+
},
34+
},
35+
});
36+
37+
// then
38+
expect(response.statusCode).to.equal(201);
39+
40+
const createdEvent = await knex('passage-events').where({ passageId: passage.id }).first();
41+
expect(createdEvent).to.not.be.undefined;
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)