Skip to content

Commit

Permalink
feat: protect pass creation
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Oct 8, 2024
1 parent 7fb0ed6 commit de99c42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/infrastructure/PassInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ export class PassInterface {
},
},
{
method: 'GET',
method: 'POST',
path: '/pass',
options: {
pre: [{ method: (request, h) => { return this.authService.validateFromPass(request, h); } }],
handler: async (request, h) => {
return this.passController.create(request, h);
},
Expand Down
9 changes: 7 additions & 2 deletions tests/acceptance/passes_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ describe('Acceptance | Endpoints | Passes', function () {
});

it('should return pass', async function () {
const token = await generateAuthorizationToken();
await knex('reservations').insert({ code: '12345', start_at: new Date('2024-01-10'), court: '10', activity: 'Badminton', status: 'reserved', updated_at: new Date('2024-01-02') });

const response = await server.inject({
method: 'GET',
method: 'POST',
url: '/pass',
headers: { authorization: token },
});

expect(response.statusCode).to.equal(201);
Expand All @@ -243,9 +245,12 @@ describe('Acceptance | Endpoints | Passes', function () {

context('when next event does not exist', function () {
it('should return 503', async function () {
const token = await generateAuthorizationToken();

const response = await server.inject({
method: 'GET',
method: 'POST',
url: '/pass',
headers: { authorization: token },
});

expect(response.statusCode).to.equal(503);
Expand Down

0 comments on commit de99c42

Please sign in to comment.