diff --git a/api/lib/application/users/index.js b/api/lib/application/users/index.js index bea76edd86f..21dc7a70cba 100644 --- a/api/lib/application/users/index.js +++ b/api/lib/application/users/index.js @@ -215,31 +215,6 @@ const register = async function (server) { tags: ['api'], }, }, - { - method: 'GET', - path: '/api/users/{userId}/campaigns/{campaignId}/campaign-participations', - config: { - validate: { - params: Joi.object({ - userId: identifiersType.userId, - campaignId: identifiersType.campaignId, - }), - }, - pre: [ - { - method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser, - assign: 'requestedUserIsAuthenticatedUser', - }, - ], - handler: userController.getUserCampaignParticipationToCampaign, - notes: [ - '- **Cette route est restreinte aux utilisateurs authentifiés**\n' + - '- Récupération de la dernière participation d’un utilisateur (**userId**) à une campagne donnée (**campaignId**)\n' + - '- L’id demandé doit correspondre à celui de l’utilisateur authentifié', - ], - tags: ['api', 'user', 'campaign', 'campaign-participations'], - }, - }, { method: 'GET', path: '/api/users/{id}/trainings', diff --git a/api/src/prescription/campaign-participation/application/campaign-participation-route.js b/api/src/prescription/campaign-participation/application/campaign-participation-route.js index 7d68e7d6602..c4797cb25e8 100644 --- a/api/src/prescription/campaign-participation/application/campaign-participation-route.js +++ b/api/src/prescription/campaign-participation/application/campaign-participation-route.js @@ -258,6 +258,31 @@ const register = async function (server) { tags: ['api'], }, }, + { + method: 'GET', + path: '/api/users/{userId}/campaigns/{campaignId}/campaign-participations', + config: { + validate: { + params: Joi.object({ + userId: identifiersType.userId, + campaignId: identifiersType.campaignId, + }), + }, + pre: [ + { + method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser, + assign: 'requestedUserIsAuthenticatedUser', + }, + ], + handler: campaignParticipationController.getUserCampaignParticipationToCampaign, + notes: [ + '- **Cette route est restreinte aux utilisateurs authentifiés**\n' + + '- Récupération de la dernière participation d’un utilisateur (**userId**) à une campagne donnée (**campaignId**)\n' + + '- L’id demandé doit correspondre à celui de l’utilisateur authentifié', + ], + tags: ['api', 'user', 'campaign', 'campaign-participations'], + }, + }, ]); }; diff --git a/api/tests/acceptance/application/users/get-user-campaign-participation-to-campaign_test.js b/api/tests/acceptance/application/users/get-user-campaign-participation-to-campaign_test.js deleted file mode 100644 index 383455bc298..00000000000 --- a/api/tests/acceptance/application/users/get-user-campaign-participation-to-campaign_test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { - createServer, - databaseBuilder, - expect, - generateValidRequestAuthorizationHeader, -} from '../../../test-helper.js'; - -describe('Acceptance | Route | GET /users/id/campaigns/id/campaign-participations', function () { - let userId; - let campaign; - let campaignParticipation; - let options; - let server; - - beforeEach(async function () { - server = await createServer(); - }); - - describe('GET /users/:id/campaigns/:id/campaign-participations', function () { - beforeEach(function () { - userId = databaseBuilder.factory.buildUser().id; - campaign = databaseBuilder.factory.buildCampaign(); - campaignParticipation = databaseBuilder.factory.buildCampaignParticipation({ - userId, - campaignId: campaign.id, - status: 'SHARED', - }); - - options = { - method: 'GET', - url: `/api/users/${userId}/campaigns/${campaign.id}/campaign-participations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, - }; - - return databaseBuilder.commit(); - }); - - it('should return campaign participation with 200 HTTP status code', async function () { - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(200); - expect(response.result).to.deep.equal({ - data: { - type: 'campaign-participations', - id: campaignParticipation.id.toString(), - attributes: { - 'is-shared': true, - 'participant-external-id': campaignParticipation.participantExternalId, - 'shared-at': campaignParticipation.sharedAt, - 'deleted-at': campaignParticipation.deletedAt, - 'created-at': campaignParticipation.createdAt, - }, - relationships: { - campaign: { - data: null, - }, - trainings: { - links: { - related: `/api/campaign-participations/${campaignParticipation.id}/trainings`, - }, - }, - }, - }, - }); - }); - }); -}); diff --git a/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js b/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js index 72034d03bc6..f235751b546 100644 --- a/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js +++ b/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js @@ -848,4 +848,32 @@ describe('Acceptance | API | Campaign Participations', function () { expect(participationIds).to.deep.equals([sharableCampaignParticipation.id, startedCampaignParticipation.id]); }); }); + + describe('GET /users/{userId}/campaigns/{campaignId}/campaign-participations', function () { + let options; + + beforeEach(function () { + databaseBuilder.factory.buildCampaignParticipation({ + userId, + campaignId, + status: 'SHARED', + }); + + options = { + method: 'GET', + url: `/api/users/${userId}/campaigns/${campaignId}/campaign-participations`, + headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + }; + + return databaseBuilder.commit(); + }); + + it('should return campaign participation with 200 HTTP status code', async function () { + // when + const response = await server.inject(options); + + // then + expect(response.statusCode).to.equal(200); + }); + }); });