Skip to content

Commit

Permalink
#11 - Updated validation error reply
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders164a committed Oct 2, 2023
1 parent 7e43f6a commit 8f9fbdb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/modules/auth/__test__/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('POST /api/auth/login', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email is required', 'Password is required'],
},
Expand All @@ -113,7 +113,7 @@ describe('POST /api/auth/login', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email er påkrævet', 'Adgangskode er påkrævet'],
},
Expand All @@ -132,7 +132,7 @@ describe('POST /api/auth/login', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email is required'],
},
Expand All @@ -151,7 +151,7 @@ describe('POST /api/auth/login', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Password is required'],
},
Expand Down
20 changes: 10 additions & 10 deletions src/modules/auth/__test__/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
email: ['Email must be of correct format'],
},
Expand All @@ -90,7 +90,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email is required'],
},
Expand All @@ -111,7 +111,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
email: ['Email must be of correct format'],
},
Expand All @@ -131,7 +131,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Password is required'],
},
Expand All @@ -152,7 +152,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
password: ['Password must be atleast 8 characters'],
},
Expand All @@ -173,7 +173,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
password: ['Password must be atleast 8 characters'],
},
Expand All @@ -193,7 +193,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Name is required'],
},
Expand All @@ -214,7 +214,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
name: ['You must choose a name'],
},
Expand All @@ -231,7 +231,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email is required', 'Password is required', 'Name is required'],
},
Expand All @@ -251,7 +251,7 @@ describe('POST /api/auth/register', () => {

expect(response.statusCode).toBe(400);
expect(response.json()).toMatchObject({
error: 'Bad Request',
error: 'ValidationError',
errors: {
_: ['Email er påkrævet', 'Adgangskode er påkrævet', 'Navn er påkrævet'],
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/error.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default fastifyPlugin(async (fastify: FastifyInstance) => {
});

return reply.status(400).send({
error: 'Bad Request',
error: 'ValidationError',
errors: errors,
statusCode: 400,
});
Expand Down

0 comments on commit 8f9fbdb

Please sign in to comment.