Skip to content

Commit

Permalink
doc: add payload in swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Jul 11, 2024
1 parent e43d6cf commit 96109c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
11 changes: 10 additions & 1 deletion lib/application/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Server } from '@hapi/hapi';
import Joi from 'joi';

import { authenticate } from './authentication.js';

const register = async function (server: Server) {
Expand All @@ -8,11 +10,18 @@ const register = async function (server: Server) {
path: '/token',
options: {
auth: false,
validate: {
payload: Joi.object({
user: Joi.string().required(),
password: Joi.string().required(),
}).label('AuthenticationPayload'),
},
handler: authenticate,
tags: ['api', 'authentication'],
},
},
]);
};

const name = 'authentication-api';
export { register, name };
export { name, register };
19 changes: 18 additions & 1 deletion lib/application/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Server } from '@hapi/hapi';
import Joi from 'joi';

import { execute } from './query.js';

const register = async function (server: Server) {
Expand All @@ -7,11 +9,26 @@ const register = async function (server: Server) {
method: 'POST',
path: '/query',
options: {
validate: {
payload: Joi.object({
queryId: Joi.string().uuid().required(),
params: Joi.array()
.items(
Joi.object({
name: Joi.string().required(),
value: Joi.any().required(),
}).label('QueryParameter'),
)
.required()
.label('QueryParameters'),
}).label('QueryPayload'),
},
handler: execute,
tags: ['api', 'query'],
},
},
]);
};

const name = 'query-api';
export { register, name };
export { name, register };
1 change: 1 addition & 0 deletions lib/application/query/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Request, ResponseObject, ResponseToolkit } from '@hapi/hapi';

import { UserCommand } from '../../domain/commands/UserCommand.js';
import type { Result } from '../../domain/models/Result.js';
import { executeQueryUseCase } from '../../domain/usecases/ExecuteQueryUsecase.js';
Expand Down
10 changes: 4 additions & 6 deletions tests/acceptance/application/query_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ describe('Acceptance | query', function () {
// then
expect(response.statusCode).to.equal(400);
expect(JSON.parse(response.payload)).to.deep.equal({
status: 'failure',
messages: [
'unknown attribute: "queryIdddddddd"',
'"queryId" is mandatory',
],
statusCode: 400,
error: 'Bad Request',
message: 'Invalid request payload input',
});
});
});
Expand Down Expand Up @@ -136,7 +134,7 @@ describe('Acceptance | query', function () {
it('should return a proper error response with status code 422', async function () {
// given
const queryId = '26f6efcc-ce13-4b20-b6ea-5bebae6115af';
const otherQueryId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
const otherQueryId = '11a1aaaa-aa11-1a11-a1aa-1aaaaa1111aa';
await knexAPI('catalog_queries').insert({
id: otherQueryId,
sql_query: 'SELECT COUNT(*) FROM public.data_ref_academies',
Expand Down

0 comments on commit 96109c6

Please sign in to comment.