Skip to content

Commit

Permalink
🚧 Add schema with validation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobrunodev committed Nov 26, 2019
1 parent 40aa168 commit c8d43e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/api/components/user/user.controller.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/* eslint-disable import/prefer-default-export */
import mail from '../../lib/mail.lib';

export async function sendUserConfirmationEmail({ body }, res) {
export async function sendUserConfirmationEmail(
{ body, validationError },
res
) {
if (validationError) {
res.code(400).send(validationError);
}

try {
const { email: to, link, sandbox } = body;
const email = {
to,
subject: 'teste do teste',
subject: 'CollabCode Training - Confirmação de conta',
html: `
Olá!<br>
Por favor, confirme sua conta da <b>CollabCode Training</b> clicando no link a seguir: <a href="${link}">${link}</a>
Expand Down
3 changes: 2 additions & 1 deletion src/api/components/user/user.routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { sendUserConfirmationEmail } from './user.controller';
import schema from './user.schema';

function userRoutes(server) {
server.post('/user/confirmation', sendUserConfirmationEmail);
server.post('/user/confirmation', { schema }, sendUserConfirmationEmail);
}

export default userRoutes;
6 changes: 6 additions & 0 deletions test/components/user/user.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ describe(`${path}`, () => {
expect(_data.email).toEqual(body.email);
expect(_data.link).toEqual(body.link);
});

it('should return status 400 when not send the body', async () => {
const { status } = await request(server).post(`${path}/confirmation`);

expect(status).toEqual(400);
});
});
});

0 comments on commit c8d43e0

Please sign in to comment.