From 78eef818d62c4439f48ad4f28175843a386f5a38 Mon Sep 17 00:00:00 2001 From: Berlem Date: Fri, 19 Apr 2024 19:10:10 +0200 Subject: [PATCH] update logic and tests to token authorization #407 --- staff/belen-ivars/project/api/index.js | 4 ++-- staff/belen-ivars/project/api/logic/createRecipe.js | 2 +- staff/belen-ivars/project/api/logic/createRecipe.test.js | 2 +- staff/belen-ivars/project/api/logic/deleteRecipe.test.js | 2 +- staff/belen-ivars/project/api/logic/retrieveRecipes.js | 1 - staff/belen-ivars/project/api/test/create-recipe.test.sh | 5 +++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/staff/belen-ivars/project/api/index.js b/staff/belen-ivars/project/api/index.js index b8b3c8b7e..2d254894a 100644 --- a/staff/belen-ivars/project/api/index.js +++ b/staff/belen-ivars/project/api/index.js @@ -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) diff --git a/staff/belen-ivars/project/api/logic/createRecipe.js b/staff/belen-ivars/project/api/logic/createRecipe.js index b496f024b..9d42f1b12 100644 --- a/staff/belen-ivars/project/api/logic/createRecipe.js +++ b/staff/belen-ivars/project/api/logic/createRecipe.js @@ -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) diff --git a/staff/belen-ivars/project/api/logic/createRecipe.test.js b/staff/belen-ivars/project/api/logic/createRecipe.test.js index 389c0ec39..6dcc2cddb 100644 --- a/staff/belen-ivars/project/api/logic/createRecipe.test.js +++ b/staff/belen-ivars/project/api/logic/createRecipe.test.js @@ -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) { diff --git a/staff/belen-ivars/project/api/logic/deleteRecipe.test.js b/staff/belen-ivars/project/api/logic/deleteRecipe.test.js index 01c4c217e..25aa81958 100644 --- a/staff/belen-ivars/project/api/logic/deleteRecipe.test.js +++ b/staff/belen-ivars/project/api/logic/deleteRecipe.test.js @@ -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) { diff --git a/staff/belen-ivars/project/api/logic/retrieveRecipes.js b/staff/belen-ivars/project/api/logic/retrieveRecipes.js index 34cdb39f5..41b67cd7f 100644 --- a/staff/belen-ivars/project/api/logic/retrieveRecipes.js +++ b/staff/belen-ivars/project/api/logic/retrieveRecipes.js @@ -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 diff --git a/staff/belen-ivars/project/api/test/create-recipe.test.sh b/staff/belen-ivars/project/api/test/create-recipe.test.sh index a808e9db3..94def0221 100755 --- a/staff/belen-ivars/project/api/test/create-recipe.test.sh +++ b/staff/belen-ivars/project/api/test/create-recipe.test.sh @@ -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