From 9c10594cfaf753e63084af5faccd2e33f0fc6e6d Mon Sep 17 00:00:00 2001 From: Benjamin Petetot Date: Tue, 19 Nov 2024 16:57:45 +0100 Subject: [PATCH] feat(api): add relationship to my-account in GET users/me --- .../application/user/user.route.js | 2 +- .../serializers/jsonapi/user-with-activity.serializer.js | 7 +++++++ .../acceptance/application/user/user.route.test.js | 7 ++++++- .../jsonapi/user-with-activity.serializer.test.js | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/src/identity-access-management/application/user/user.route.js b/api/src/identity-access-management/application/user/user.route.js index 48151b477e8..cfd021438fd 100644 --- a/api/src/identity-access-management/application/user/user.route.js +++ b/api/src/identity-access-management/application/user/user.route.js @@ -87,7 +87,7 @@ export const userRoutes = [ handler: (request, h) => userController.getCurrentUserAccountInfo(request, h), notes: [ '- **Cette route est restreinte aux utilisateurs authentifiés**\n' + - '- Récupération des information de compte utilisateur\n', + '- Récupération des informations du compte utilisateur authentifié\n', ], tags: ['identity-access-management', 'api', 'user', 'my-account'], }, diff --git a/api/src/identity-access-management/infrastructure/serializers/jsonapi/user-with-activity.serializer.js b/api/src/identity-access-management/infrastructure/serializers/jsonapi/user-with-activity.serializer.js index ebcb11e9746..e0bdbd1c397 100644 --- a/api/src/identity-access-management/infrastructure/serializers/jsonapi/user-with-activity.serializer.js +++ b/api/src/identity-access-management/infrastructure/serializers/jsonapi/user-with-activity.serializer.js @@ -18,6 +18,7 @@ const serialize = function (users, meta) { 'pixCertifTermsOfServiceAccepted', 'lang', 'isAnonymous', + 'accountInfo', 'profile', 'hasSeenAssessmentInstructions', 'isCertifiable', @@ -60,6 +61,12 @@ const serialize = function (users, meta) { }, }, }, + accountInfo: { + ref: 'id', + ignoreRelationshipData: true, + nullIfMissing: true, + relationshipLinks: { related: () => '/api/users/my-account' }, + }, meta, }).serialize(users); }; diff --git a/api/tests/identity-access-management/acceptance/application/user/user.route.test.js b/api/tests/identity-access-management/acceptance/application/user/user.route.test.js index 87da799f397..c189b80fdc3 100644 --- a/api/tests/identity-access-management/acceptance/application/user/user.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/user/user.route.test.js @@ -232,6 +232,11 @@ describe('Acceptance | Identity Access Management | Application | Route | User', 'last-data-protection-policy-seen-at': null, }, relationships: { + 'account-info': { + links: { + related: '/api/users/my-account', + }, + }, profile: { links: { related: `/api/users/${user.id}/profile`, @@ -277,7 +282,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', expect(response.statusCode).to.equal(200); expect(response.result).to.deep.equal({ data: { - type: 'my-accounts', + type: 'account-infos', id: user.id.toString(), attributes: { 'can-self-delete-account': false, diff --git a/api/tests/identity-access-management/unit/infrastructure/serializers/jsonapi/user-with-activity.serializer.test.js b/api/tests/identity-access-management/unit/infrastructure/serializers/jsonapi/user-with-activity.serializer.test.js index 3484d496586..50a9beea57b 100644 --- a/api/tests/identity-access-management/unit/infrastructure/serializers/jsonapi/user-with-activity.serializer.test.js +++ b/api/tests/identity-access-management/unit/infrastructure/serializers/jsonapi/user-with-activity.serializer.test.js @@ -65,6 +65,11 @@ describe('Unit | Identity Access Management | Infrastructure | Serializer | JSON userModelObject.shouldSeeDataProtectionPolicyInformationBanner, }, relationships: { + 'account-info': { + links: { + related: '/api/users/my-account', + }, + }, profile: { links: { related: `/api/users/${userModelObject.id}/profile`,