Skip to content

Commit

Permalink
tech(api): migrate route
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Nov 13, 2024
1 parent f5aafd0 commit d76905f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 94 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 @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
]);
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit d76905f

Please sign in to comment.