-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): Unification of error messages for better end to end test…
…ing.
- Loading branch information
1 parent
2711820
commit 50a7f72
Showing
5 changed files
with
244 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,31 @@ | ||
'use strict'; | ||
|
||
function validateCreate (request, response, next) { | ||
// No need to check for no body, express will make body an empty object | ||
const {name, stock, id} = request.body; | ||
|
||
if (!name) { | ||
response.status(400); | ||
return response.send('The name must not be null'); | ||
function validateCreateUpdateRequest(request, response, next) { | ||
if(Object.keys(request.body).length === 0){ | ||
response.status(415); | ||
return response.send('Invalid payload!'); | ||
} | ||
|
||
if (!stock) { | ||
response.status(400); | ||
return response.send('The stock must not be greater or equal to 0'); | ||
} | ||
|
||
if (id) { | ||
response.status(400); | ||
return response.send('The created item already contains an id'); | ||
} | ||
|
||
next(); | ||
} | ||
|
||
function validateUpdate (request, response, next) { | ||
// No need to check for no body, express will make body an empty object | ||
const {name, stock, id} = request.body; | ||
const { name, stock, id } = request.body; | ||
|
||
if (!name) { | ||
response.status(400); | ||
return response.send('The name must not be null'); | ||
response.status(422); | ||
return response.send('The name is required!'); | ||
} | ||
|
||
if (!stock) { | ||
response.status(400); | ||
return response.send('The stock must not be greater or equal to 0'); | ||
if (stock == null || isNaN(stock) || stock < 0) { | ||
response.status(422); | ||
return response.send('The stock must be greater or equal to 0!'); | ||
} | ||
|
||
if (id && id !== request.params.id) { | ||
response.status(400); | ||
return response.send('The id cannot be changed'); | ||
response.status(422); | ||
return response.send('Id was invalidly set on request.'); | ||
} | ||
|
||
next(); | ||
} | ||
|
||
module.exports = { | ||
validateCreate, | ||
validateUpdate | ||
validateCreateUpdateRequest | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.