Skip to content

Commit

Permalink
update logic and tests to token authorization b00tc4mp#407
Browse files Browse the repository at this point in the history
  • Loading branch information
berlem committed Apr 19, 2024
1 parent bf63bb7 commit 78eef81
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions staff/belen-ivars/project/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ mongoose.connect(process.env.MONGODB_URL)

server.post('/users/auth', jsonBodyParser, authenticateUserHandler)

server.get('/users/:id', retrieveUserHandler)
server.get('/users', retrieveUserHandler)

server.post('/recipes', jsonBodyParser, createRecipeHandler)

server.get('/recipes/', retrieveRecipesHandler)
server.get('/recipes', retrieveRecipesHandler)

server.delete('/recipes/:recipeId', deleteRecipeHandler)

Expand Down
2 changes: 1 addition & 1 deletion staff/belen-ivars/project/api/logic/createRecipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function createRecipe(userId, title, description, image) {
validate.text(title, 'title')
validate.text(description, 'description')
validate.text(image, 'image')
validate.id(userId, 'id')
// validate.id(userId, 'id')

const user = await User.findById(userId)

Expand Down
2 changes: 1 addition & 1 deletion staff/belen-ivars/project/api/logic/createRecipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import createRecipe from './createRecipe.js'
(async () => {
await mongoose.connect(process.env.MONGODB_URL)
try {
await createRecipe('65d655fac1dd88f9aee917d6', 'Colors', 'Persona con pintura corporal', 'https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/')
await createRecipe('65d655fac1dd88f9aee917d6', 'Revuelto de setas y gula', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ut neque ut ante mollis ultricies sed sit amet lacus. Nam dignissim urna vel porttitor placerat. ', 'https://recetasdecocina.elmundo.es/wp-content/uploads/2015/09/revuelto-de-setas-receta.jpg')

console.log('recipe has been published')
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion staff/belen-ivars/project/api/logic/deleteRecipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import deleteRecipe from './deleteRecipe.js'
(async () => {
await mongoose.connect(process.env.MONGODB_URL)
try {
await deleteRecipe('65d656eaa92e85c9f9fa6d71', '65f97adbd699fa7945c5d178')
await deleteRecipe('65d655fac1dd88f9aee917d6', '66228dc49dc5795e811889ad')

console.log('recipe has been deleted')
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion staff/belen-ivars/project/api/logic/retrieveRecipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async function retrieveRecipes(id) {
throw new NotFoundError('No user found')
}

console.log('user exists')
const recipes = await Recipe.find()

return recipes
Expand Down
5 changes: 3 additions & 2 deletions staff/belen-ivars/project/api/test/create-recipe.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ TEST 'create-recipe'
CASE 'success on current user'

curl 'http://localhost:9000/recipes' \
-H 'Content-Type: application/json' \
-d '{"author": "65d655fac1dd88f9aee917d6", "title": "Colors", "description": "Persona con pintura corporal", "image":"https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/"}' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NWY4NWFjNzg4M2ZkMzcxM2M4YmQzYTMiLCJpYXQiOjE3MTM1NDA2MzUsImV4cCI6MTcxMzU0NDIzNX0.Efh41YYJ_ij9y80tTrhVBqQbWwzoRcHxqjDQSUuXzO8' \
-H 'Content-Type: application/json' \
-d '{"title": "Revuelto setas y gula", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ut neque ut ante mollis ultricies sed sit amet lacus. Nam dignissim urna vel porttitor placerat. ", "image":"https://recetasdecocina.elmundo.es/wp-content/uploads/2015/09/revuelto-de-setas-receta.jpg"}' \
-v

# > POST /recipes HTTP/1.1
Expand Down

0 comments on commit 78eef81

Please sign in to comment.