Skip to content

Commit

Permalink
[TECH] Migrer la route de mise à jour Has Seen Assessment Instructions (
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Dec 4, 2024
2 parents 18c040e + be3d8ea commit 7a83571
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 70 deletions.
25 changes: 0 additions & 25 deletions api/lib/application/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,6 @@ const register = async function (server) {
tags: ['api', 'user', 'trainings'],
},
},
{
method: 'PATCH',
path: '/api/users/{id}/remember-user-has-seen-assessment-instructions',
config: {
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
validate: {
params: Joi.object({
id: identifiersType.userId,
}),
},
handler: userController.rememberUserHasSeenAssessmentInstructions,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Sauvegarde le fait que l'utilisateur ait vu le didacticiel" +
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
"- Le contenu de la requête n'est pas pris en compte.",
],
tags: ['api', 'user'],
},
},
{
method: 'PATCH',
path: '/api/users/{id}/has-seen-challenge-tooltip/{challengeType}',
Expand Down
8 changes: 0 additions & 8 deletions api/lib/application/users/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import * as requestResponseUtils from '../../../src/shared/infrastructure/utils/
import { usecases } from '../../domain/usecases/index.js';
import * as userOrganizationForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-organization-for-admin-serializer.js';

const rememberUserHasSeenAssessmentInstructions = async function (request, h, dependencies = { userSerializer }) {
const authenticatedUserId = request.auth.credentials.userId;

const updatedUser = await usecases.rememberUserHasSeenAssessmentInstructions({ userId: authenticatedUserId });
return dependencies.userSerializer.serialize(updatedUser);
};

const rememberUserHasSeenChallengeTooltip = async function (request, h, dependencies = { userSerializer }) {
const authenticatedUserId = request.auth.credentials.userId;
const challengeType = request.params.challengeType;
Expand Down Expand Up @@ -117,7 +110,6 @@ const userController = {
findPaginatedUserRecommendedTrainings,
findUserOrganizationsForAdmin,
reassignAuthenticationMethods,
rememberUserHasSeenAssessmentInstructions,
rememberUserHasSeenChallengeTooltip,
resetScorecard,
};
Expand Down
25 changes: 25 additions & 0 deletions api/src/evaluation/application/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ const register = async function (server) {
tags: ['api', 'user'],
},
},
{
method: 'PATCH',
path: '/api/users/{id}/remember-user-has-seen-assessment-instructions',
config: {
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
validate: {
params: Joi.object({
id: identifiersType.userId,
}),
},
handler: userController.rememberUserHasSeenAssessmentInstructions,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Sauvegarde le fait que l'utilisateur ait vu le didacticiel" +
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
"- Le contenu de la requête n'est pas pris en compte.",
],
tags: ['api', 'user'],
},
},
]);
};

Expand Down
12 changes: 11 additions & 1 deletion api/src/evaluation/application/users/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const rememberUserHasSeenNewDashboardInfo = async function (request, h, dependen
return dependencies.userSerializer.serialize(updatedUser);
};

const userController = { rememberUserHasSeenNewDashboardInfo };
const rememberUserHasSeenAssessmentInstructions = async function (request, h, dependencies = { userSerializer }) {
const authenticatedUserId = request.auth.credentials.userId;

const updatedUser = await usecases.rememberUserHasSeenAssessmentInstructions({ userId: authenticatedUserId });
return dependencies.userSerializer.serialize(updatedUser);
};

const userController = {
rememberUserHasSeenNewDashboardInfo,
rememberUserHasSeenAssessmentInstructions,
};

export { userController };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rememberUserHasSeenAssessmentInstructions = function ({ userId, userRepository }) {
return userRepository.updateHasSeenAssessmentInstructionsToTrue(userId);
return userRepository.updateAssessmentInstructionsInfoAsSeen({ userId });
};

export { rememberUserHasSeenAssessmentInstructions };
14 changes: 12 additions & 2 deletions api/src/evaluation/infrastructure/repositories/user-repository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import ("./index.js").UserApi} UserApi
* @typedef {import ('./index.js').UserApi} UserApi
*/

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

export { updateHasSeenNewDashboardInfo };
/**
* @function
* @param {Object} params
* @param {UserApi} params.userApi
* @param {number} params.userId
*/
const updateAssessmentInstructionsInfoAsSeen = async function ({ userId, userApi }) {
return userApi.markAssessmentInstructionsInfoAsSeen({ userId });
};

export { updateAssessmentInstructionsInfoAsSeen, updateHasSeenNewDashboardInfo };
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const markNewDashboardInfoAsSeen = async ({ userId }) => {
return usecases.markUserHasSeenNewDashboardInfo({ userId });
};

export const markAssessmentInstructionsInfoAsSeen = async ({ userId }) => {
return usecases.markAssessmentInstructionsInfoAsSeen({ userId });
};

export const getUserDetailsByUserIds = async ({ userIds }) => {
const users = await usecases.getUserDetailsByUserIds({ userIds });
return users.map((user) => new UserDTO(user));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @typedef {import ('../../domain/usecases/index.js').UserRepository} UserRepository
*/

/**
* @param {Object} params
* @param {number} params.userId
* @param {UserRepository} params.userRepository
*/
const markAssessmentInstructionsInfoAsSeen = function ({ userId, userRepository }) {
return userRepository.updateHasSeenAssessmentInstructionsToTrue(userId);
};

export { markAssessmentInstructionsInfoAsSeen };
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@ describe('Unit | Controller | user-controller', function () {
expect(response).to.be.equal('ok');
});
});

describe('#rememberUserHasSeenAssessmentInstructions', function () {
let request;
let userSerializer;
const userId = 1;

beforeEach(function () {
request = {
auth: { credentials: { userId } },
params: { id: userId },
};
userSerializer = {
serialize: sinon.stub(),
};

sinon.stub(evaluationUsecases, 'rememberUserHasSeenAssessmentInstructions');
});

it('should remember user has seen assessment instructions', async function () {
// given
evaluationUsecases.rememberUserHasSeenAssessmentInstructions.withArgs({ userId }).resolves({});
userSerializer.serialize.withArgs({}).returns('ok');

// when
const response = await userController.rememberUserHasSeenAssessmentInstructions(request, hFake, {
userSerializer,
});

// then
expect(response).to.be.equal('ok');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { rememberUserHasSeenAssessmentInstructions } from '../../../../lib/domain/usecases/remember-user-has-seen-assessment-instructions.js';
import { expect, sinon } from '../../../test-helper.js';
import { rememberUserHasSeenAssessmentInstructions } from '../../../../../src/evaluation/domain/usecases/remember-user-has-seen-assessment-instructions.js';
import { expect, sinon } from '../../../../test-helper.js';

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

beforeEach(function () {
userRepository = { updateHasSeenAssessmentInstructionsToTrue: sinon.stub() };
userRepository = { updateAssessmentInstructionsInfoAsSeen: sinon.stub() };
});

it('should update has seen assessment instructions', async function () {
// given
const userId = 'userId';
const updatedUser = Symbol('updateduser');
userRepository.updateHasSeenAssessmentInstructionsToTrue.resolves(updatedUser);
userRepository.updateAssessmentInstructionsInfoAsSeen.resolves(updatedUser);

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

// then
expect(userRepository.updateHasSeenAssessmentInstructionsToTrue).to.have.been.calledWithExactly(userId);
expect(userRepository.updateAssessmentInstructionsInfoAsSeen).to.have.been.calledWithExactly({ userId });
expect(actualUpdatedUser).to.equal(updatedUser);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
import { databaseBuilder, expect } from '../../../../test-helper.js';

describe('Integration | Identity Access Management | Domain | UseCase | markAssessmentInstructionsInfoAsSeen', function () {
it('should update hasSeenAssessmentInstructions property as true for the user', async function () {
// given
const user = databaseBuilder.factory.buildUser({
email: '[email protected]',
hasSeenAssessmentInstructions: false,
});
await databaseBuilder.commit();

// when
const result = await usecases.markAssessmentInstructionsInfoAsSeen({
userId: user.id,
});

// then
expect(result.hasSeenAssessmentInstructions).to.be.true;
});
});
28 changes: 0 additions & 28 deletions api/tests/unit/application/users/user-controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,6 @@ describe('Unit | Controller | user-controller', function () {
};
});

describe('#rememberUserHasSeenAssessmentInstructions', function () {
let request;
const userId = 1;

beforeEach(function () {
request = {
auth: { credentials: { userId } },
params: { id: userId },
};

sinon.stub(usecases, 'rememberUserHasSeenAssessmentInstructions');
});

it('should remember user has seen assessment instructions', async function () {
// given
usecases.rememberUserHasSeenAssessmentInstructions.withArgs({ userId }).resolves({});
userSerializer.serialize.withArgs({}).returns('ok');

// when
const response = await userController.rememberUserHasSeenAssessmentInstructions(request, hFake, {
userSerializer,
});

// then
expect(response).to.be.equal('ok');
});
});

describe('#rememberUserHasSeenChallengeTooltip', function () {
let request;
const userId = 1;
Expand Down

0 comments on commit 7a83571

Please sign in to comment.