Skip to content

Commit a92a2e0

Browse files
pix-service-auto-mergeHEYGUL
authored andcommitted
[TECH] Migrer la route de mise à jour Has Seen Assessment Instructions (PIX-14725).
#10677
2 parents af0eaa6 + cfd24a0 commit a92a2e0

File tree

12 files changed

+125
-70
lines changed

12 files changed

+125
-70
lines changed

api/lib/application/users/index.js

-25
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,6 @@ const register = async function (server) {
156156
tags: ['api', 'user', 'trainings'],
157157
},
158158
},
159-
{
160-
method: 'PATCH',
161-
path: '/api/users/{id}/remember-user-has-seen-assessment-instructions',
162-
config: {
163-
pre: [
164-
{
165-
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
166-
assign: 'requestedUserIsAuthenticatedUser',
167-
},
168-
],
169-
validate: {
170-
params: Joi.object({
171-
id: identifiersType.userId,
172-
}),
173-
},
174-
handler: userController.rememberUserHasSeenAssessmentInstructions,
175-
notes: [
176-
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
177-
"- Sauvegarde le fait que l'utilisateur ait vu le didacticiel" +
178-
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
179-
"- Le contenu de la requête n'est pas pris en compte.",
180-
],
181-
tags: ['api', 'user'],
182-
},
183-
},
184159
{
185160
method: 'PATCH',
186161
path: '/api/users/{id}/has-seen-challenge-tooltip/{challengeType}',

api/lib/application/users/user-controller.js

-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ import * as requestResponseUtils from '../../../src/shared/infrastructure/utils/
99
import { usecases } from '../../domain/usecases/index.js';
1010
import * as userOrganizationForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-organization-for-admin-serializer.js';
1111

12-
const rememberUserHasSeenAssessmentInstructions = async function (request, h, dependencies = { userSerializer }) {
13-
const authenticatedUserId = request.auth.credentials.userId;
14-
15-
const updatedUser = await usecases.rememberUserHasSeenAssessmentInstructions({ userId: authenticatedUserId });
16-
return dependencies.userSerializer.serialize(updatedUser);
17-
};
18-
1912
const rememberUserHasSeenChallengeTooltip = async function (request, h, dependencies = { userSerializer }) {
2013
const authenticatedUserId = request.auth.credentials.userId;
2114
const challengeType = request.params.challengeType;
@@ -117,7 +110,6 @@ const userController = {
117110
findPaginatedUserRecommendedTrainings,
118111
findUserOrganizationsForAdmin,
119112
reassignAuthenticationMethods,
120-
rememberUserHasSeenAssessmentInstructions,
121113
rememberUserHasSeenChallengeTooltip,
122114
resetScorecard,
123115
};

api/src/evaluation/application/users/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ const register = async function (server) {
3131
tags: ['api', 'user'],
3232
},
3333
},
34+
{
35+
method: 'PATCH',
36+
path: '/api/users/{id}/remember-user-has-seen-assessment-instructions',
37+
config: {
38+
pre: [
39+
{
40+
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
41+
assign: 'requestedUserIsAuthenticatedUser',
42+
},
43+
],
44+
validate: {
45+
params: Joi.object({
46+
id: identifiersType.userId,
47+
}),
48+
},
49+
handler: userController.rememberUserHasSeenAssessmentInstructions,
50+
notes: [
51+
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
52+
"- Sauvegarde le fait que l'utilisateur ait vu le didacticiel" +
53+
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
54+
"- Le contenu de la requête n'est pas pris en compte.",
55+
],
56+
tags: ['api', 'user'],
57+
},
58+
},
3459
]);
3560
};
3661

api/src/evaluation/application/users/user-controller.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ const rememberUserHasSeenNewDashboardInfo = async function (request, h, dependen
88
return dependencies.userSerializer.serialize(updatedUser);
99
};
1010

11-
const userController = { rememberUserHasSeenNewDashboardInfo };
11+
const rememberUserHasSeenAssessmentInstructions = async function (request, h, dependencies = { userSerializer }) {
12+
const authenticatedUserId = request.auth.credentials.userId;
13+
14+
const updatedUser = await usecases.rememberUserHasSeenAssessmentInstructions({ userId: authenticatedUserId });
15+
return dependencies.userSerializer.serialize(updatedUser);
16+
};
17+
18+
const userController = {
19+
rememberUserHasSeenNewDashboardInfo,
20+
rememberUserHasSeenAssessmentInstructions,
21+
};
1222

1323
export { userController };
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const rememberUserHasSeenAssessmentInstructions = function ({ userId, userRepository }) {
2-
return userRepository.updateHasSeenAssessmentInstructionsToTrue(userId);
2+
return userRepository.updateAssessmentInstructionsInfoAsSeen({ userId });
33
};
44

55
export { rememberUserHasSeenAssessmentInstructions };

api/src/evaluation/infrastructure/repositories/user-repository.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import ("./index.js").UserApi} UserApi
2+
* @typedef {import ('./index.js').UserApi} UserApi
33
*/
44

55
/**
@@ -12,4 +12,14 @@ const updateHasSeenNewDashboardInfo = async function ({ userId, userApi }) {
1212
return userApi.markNewDashboardInfoAsSeen({ userId });
1313
};
1414

15-
export { updateHasSeenNewDashboardInfo };
15+
/**
16+
* @function
17+
* @param {Object} params
18+
* @param {UserApi} params.userApi
19+
* @param {number} params.userId
20+
*/
21+
const updateAssessmentInstructionsInfoAsSeen = async function ({ userId, userApi }) {
22+
return userApi.markAssessmentInstructionsInfoAsSeen({ userId });
23+
};
24+
25+
export { updateAssessmentInstructionsInfoAsSeen, updateHasSeenNewDashboardInfo };

api/src/identity-access-management/application/api/users-api.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export const markNewDashboardInfoAsSeen = async ({ userId }) => {
88
return usecases.markUserHasSeenNewDashboardInfo({ userId });
99
};
1010

11+
export const markAssessmentInstructionsInfoAsSeen = async ({ userId }) => {
12+
return usecases.markAssessmentInstructionsInfoAsSeen({ userId });
13+
};
14+
1115
export const getUserDetailsByUserIds = async ({ userIds }) => {
1216
const users = await usecases.getUserDetailsByUserIds({ userIds });
1317
return users.map((user) => new UserDTO(user));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @typedef {import ('../../domain/usecases/index.js').UserRepository} UserRepository
3+
*/
4+
5+
/**
6+
* @param {Object} params
7+
* @param {number} params.userId
8+
* @param {UserRepository} params.userRepository
9+
*/
10+
const markAssessmentInstructionsInfoAsSeen = function ({ userId, userRepository }) {
11+
return userRepository.updateHasSeenAssessmentInstructionsToTrue(userId);
12+
};
13+
14+
export { markAssessmentInstructionsInfoAsSeen };

api/tests/evaluation/unit/application/users/user-controller_test.js

+32
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,36 @@ describe('Unit | Controller | user-controller', function () {
2929
expect(response).to.be.equal('ok');
3030
});
3131
});
32+
33+
describe('#rememberUserHasSeenAssessmentInstructions', function () {
34+
let request;
35+
let userSerializer;
36+
const userId = 1;
37+
38+
beforeEach(function () {
39+
request = {
40+
auth: { credentials: { userId } },
41+
params: { id: userId },
42+
};
43+
userSerializer = {
44+
serialize: sinon.stub(),
45+
};
46+
47+
sinon.stub(evaluationUsecases, 'rememberUserHasSeenAssessmentInstructions');
48+
});
49+
50+
it('should remember user has seen assessment instructions', async function () {
51+
// given
52+
evaluationUsecases.rememberUserHasSeenAssessmentInstructions.withArgs({ userId }).resolves({});
53+
userSerializer.serialize.withArgs({}).returns('ok');
54+
55+
// when
56+
const response = await userController.rememberUserHasSeenAssessmentInstructions(request, hFake, {
57+
userSerializer,
58+
});
59+
60+
// then
61+
expect(response).to.be.equal('ok');
62+
});
63+
});
3264
});
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { rememberUserHasSeenAssessmentInstructions } from '../../../../lib/domain/usecases/remember-user-has-seen-assessment-instructions.js';
2-
import { expect, sinon } from '../../../test-helper.js';
1+
import { rememberUserHasSeenAssessmentInstructions } from '../../../../../src/evaluation/domain/usecases/remember-user-has-seen-assessment-instructions.js';
2+
import { expect, sinon } from '../../../../test-helper.js';
33

44
describe('Unit | UseCase | remember-user-has-seen-assessment-instructions', function () {
55
let userRepository;
66

77
beforeEach(function () {
8-
userRepository = { updateHasSeenAssessmentInstructionsToTrue: sinon.stub() };
8+
userRepository = { updateAssessmentInstructionsInfoAsSeen: sinon.stub() };
99
});
1010

1111
it('should update has seen assessment instructions', async function () {
1212
// given
1313
const userId = 'userId';
1414
const updatedUser = Symbol('updateduser');
15-
userRepository.updateHasSeenAssessmentInstructionsToTrue.resolves(updatedUser);
15+
userRepository.updateAssessmentInstructionsInfoAsSeen.resolves(updatedUser);
1616

1717
// when
1818
const actualUpdatedUser = await rememberUserHasSeenAssessmentInstructions({ userId, userRepository });
1919

2020
// then
21-
expect(userRepository.updateHasSeenAssessmentInstructionsToTrue).to.have.been.calledWithExactly(userId);
21+
expect(userRepository.updateAssessmentInstructionsInfoAsSeen).to.have.been.calledWithExactly({ userId });
2222
expect(actualUpdatedUser).to.equal(updatedUser);
2323
});
2424
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
2+
import { databaseBuilder, expect } from '../../../../test-helper.js';
3+
4+
describe('Integration | Identity Access Management | Domain | UseCase | markAssessmentInstructionsInfoAsSeen', function () {
5+
it('should update hasSeenAssessmentInstructions property as true for the user', async function () {
6+
// given
7+
const user = databaseBuilder.factory.buildUser({
8+
email: 'myusertoupdate@example.net',
9+
hasSeenAssessmentInstructions: false,
10+
});
11+
await databaseBuilder.commit();
12+
13+
// when
14+
const result = await usecases.markAssessmentInstructionsInfoAsSeen({
15+
userId: user.id,
16+
});
17+
18+
// then
19+
expect(result.hasSeenAssessmentInstructions).to.be.true;
20+
});
21+
});

api/tests/unit/application/users/user-controller_test.js

-28
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,6 @@ describe('Unit | Controller | user-controller', function () {
1717
};
1818
});
1919

20-
describe('#rememberUserHasSeenAssessmentInstructions', function () {
21-
let request;
22-
const userId = 1;
23-
24-
beforeEach(function () {
25-
request = {
26-
auth: { credentials: { userId } },
27-
params: { id: userId },
28-
};
29-
30-
sinon.stub(usecases, 'rememberUserHasSeenAssessmentInstructions');
31-
});
32-
33-
it('should remember user has seen assessment instructions', async function () {
34-
// given
35-
usecases.rememberUserHasSeenAssessmentInstructions.withArgs({ userId }).resolves({});
36-
userSerializer.serialize.withArgs({}).returns('ok');
37-
38-
// when
39-
const response = await userController.rememberUserHasSeenAssessmentInstructions(request, hFake, {
40-
userSerializer,
41-
});
42-
43-
// then
44-
expect(response).to.be.equal('ok');
45-
});
46-
});
47-
4820
describe('#rememberUserHasSeenChallengeTooltip', function () {
4921
let request;
5022
const userId = 1;

0 commit comments

Comments
 (0)