Skip to content

Commit

Permalink
[TECH] Migrer la route User Has Seen New Dashboard (PIX-14451).
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Sep 27, 2024
2 parents 3d56a0d + c8bda34 commit 461871f
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 68 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 @@ -447,31 +447,6 @@ const register = async function (server) {
tags: ['api', 'user'],
},
},
{
method: 'PATCH',
path: '/api/users/{id}/has-seen-new-dashboard-info',
config: {
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
validate: {
params: Joi.object({
id: identifiersType.userId,
}),
},
handler: userController.rememberUserHasSeenNewDashboardInfo,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Sauvegarde le fait que l'utilisateur ait vu le message sur le nouveau dashboard" +
'- 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 @@ -44,13 +44,6 @@ const rememberUserHasSeenAssessmentInstructions = async function (request, h, de
return dependencies.userSerializer.serialize(updatedUser);
};

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

const updatedUser = await usecases.rememberUserHasSeenNewDashboardInfo({ 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 @@ -269,7 +262,6 @@ const userController = {
reassignAuthenticationMethods,
rememberUserHasSeenAssessmentInstructions,
rememberUserHasSeenChallengeTooltip,
rememberUserHasSeenNewDashboardInfo,
removeAuthenticationMethod,
resetScorecard,
updateUserDetailsForAdministration,
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}/has-seen-new-dashboard-info',
config: {
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
validate: {
params: Joi.object({
id: identifiersType.userId,
}),
},
handler: userController.rememberUserHasSeenNewDashboardInfo,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Sauvegarde le fait que l'utilisateur ait vu le message sur le nouveau dashboard" +
'- 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
9 changes: 8 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,13 @@ const rememberUserHasSeenLevelSevenInfo = async function (request, h, dependenci
return dependencies.userSerializer.serialize(updatedUser);
};

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

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

const userController = { rememberUserHasSeenLevelSevenInfo, rememberUserHasSeenNewDashboardInfo };

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

export { rememberUserHasSeenLevelSevenInfo };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rememberUserHasSeenNewDashboardInfo = function ({ userId, userRepository }) {
return userRepository.updateHasSeenNewDashboardInfoToTrue(userId);
return userRepository.updateHasSeenNewDashboardInfo({ userId });
};

export { rememberUserHasSeenNewDashboardInfo };
14 changes: 12 additions & 2 deletions api/src/evaluation/infrastructure/repositories/user-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
* @param {Object} params
* @param {UserApi} params.userApi
*/
const update = async function ({ userId, userApi }) {
const updateMarkLevelSevenInfoAsSeen = async function ({ userId, userApi }) {
return userApi.markLevelSevenInfoAsSeen({ userId });
};

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

export { updateHasSeenNewDashboardInfo, updateMarkLevelSevenInfoAsSeen };
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ import { usecases } from '../../domain/usecases/index.js';
export const markLevelSevenInfoAsSeen = async ({ userId }) => {
return usecases.rememberUserHasSeenLevelSevenInformation({ userId });
};

export const markNewDashboardInfoAsSeen = async ({ userId }) => {
return usecases.markUserHasSeenNewDashboardInfo({ userId });
};
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 markUserHasSeenNewDashboardInfo = function ({ userId, userRepository }) {
return userRepository.updateHasSeenNewDashboardInfoToTrue(userId);
};

export { markUserHasSeenNewDashboardInfo };
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
databaseBuilder,
expect,
generateValidRequestAuthorizationHeader,
} from '../../../test-helper.js';
} from '../../../../test-helper.js';

describe('Acceptance | Controller | users-controller-has-seen-new-dashboard-info', function () {
let server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,31 @@ describe('Unit | Controller | user-controller', function () {
expect(response).to.be.equal(userInformationSerialized);
});
});

describe('#rememberUserHasSeenNewDashboardInfo', function () {
it('should remember user has seen new dashboard info', async function () {
// given
const userId = 1;
const userSerializer = {
serialize: sinon.stub(),
};
sinon.stub(evaluationUsecases, 'rememberUserHasSeenNewDashboardInfo');

evaluationUsecases.rememberUserHasSeenNewDashboardInfo.withArgs({ userId }).resolves({});
userSerializer.serialize.withArgs({}).returns('ok');

// when
const response = await userController.rememberUserHasSeenNewDashboardInfo(
{
auth: { credentials: { userId } },
params: { id: userId },
},
hFake,
{ userSerializer },
);

// then
expect(response).to.be.equal('ok');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { expect, sinon } from '../../../../test-helper.js';
describe('Unit | UseCase | remember-user-has-seen-level-seven-info', function () {
it('should return user information', async function () {
// given
const userRepository = { update: sinon.stub() };
const userRepository = { updateMarkLevelSevenInfoAsSeen: sinon.stub() };
const userId = 1;
userRepository.update.withArgs({ userId }).resolves();
userRepository.updateMarkLevelSevenInfoAsSeen.withArgs({ userId }).resolves();

// when
await rememberUserHasSeenLevelSevenInfo({
Expand All @@ -15,6 +15,6 @@ describe('Unit | UseCase | remember-user-has-seen-level-seven-info', function ()
});

// then
expect(userRepository.update).to.have.been.calledOnce;
expect(userRepository.updateMarkLevelSevenInfoAsSeen).to.have.been.calledOnce;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,18 @@ describe('Integration | Application | users-api', function () {
expect(actualUser.hasSeenLevelSevenInfo).to.be.true;
});
});

describe('#markNewDashboardInfoAsSeen', function () {
it('should return user information', async function () {
// given
const userId = databaseBuilder.factory.buildUser({ hasSeenNewDashboardInfo: false }).id;
await databaseBuilder.commit();

// when
const actualUser = await userApi.markNewDashboardInfoAsSeen({ userId });

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

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

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

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

it('should remember user has seen new dashboard info', async function () {
// given
usecases.rememberUserHasSeenNewDashboardInfo.withArgs({ userId }).resolves({});
userSerializer.serialize.withArgs({}).returns('ok');

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

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

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

0 comments on commit 461871f

Please sign in to comment.