import supertest from 'supertest'
import app from '../../../index'
import { generateRecipe, generateUser } from '../../utils/generate'
import { Recipe } from '../../../database/models'
describe('The update recipe process', () => {
test('should update recipe and return recipe details', async () => {
// ARRANGE
// fake user, and create a recipe for this user
const { token, user } = await generateUser()
const fakeRecipe = await generateRecipe()
const recipe = await Recipe.create({
...fakeRecipe,
userId: user.id
})
const newRecipeId = recipe.id
// create recipe object for update
const fakeRecipeForUpdate = generateRecipe()
// ACTION
// update db
const responseU = await supertest(app).put(`/api/v1/recipes/${newRecipeId}`).send({
...fakeRecipeForUpdate,
access_token: token
})
// ASSERTION
// if so good we must receive ({ recipe: updatedRecipe }, 200)
console.log(responseU.body)
expect(responseU.status).toBe(200)
const recipeNew = responseU.body.data.recipe
expect(recipeNew.title).toBe(fakeRecipeForUpdate.title)
expect(recipeNew.description).toBe(fakeRecipeForUpdate.description)
expect(recipeNew.imageUrl).toBe(fakeRecipeForUpdate.imageUrl)
expect(recipeNew.timeToCook).toBe(fakeRecipeForUpdate.timeToCook)
expect(recipeNew.ingredients).toEqual(fakeRecipeForUpdate.ingredients)
expect(recipeNew.procedure).toEqual(fakeRecipeForUpdate.procedure)
});
});
import app from '../../../index'
import { generateRecipe, generateUser } from '../../utils/generate'
import { Recipe } from '../../../database/models'
describe('The update recipe process', () => {
test('should update recipe and return recipe details', async () => {
// ARRANGE
// fake user, and create a recipe for this user
const { token, user } = await generateUser()
const fakeRecipe = await generateRecipe()
const recipe = await Recipe.create({
...fakeRecipe,
userId: user.id
})
const newRecipeId = recipe.id
// create recipe object for update
const fakeRecipeForUpdate = generateRecipe()
// ACTION
// update db
const responseU = await supertest(app).put(`/api/v1/recipes/${newRecipeId}`).send({
...fakeRecipeForUpdate,
access_token: token
})
// ASSERTION
// if so good we must receive ({ recipe: updatedRecipe }, 200)
console.log(responseU.body)
expect(responseU.status).toBe(200)
const recipeNew = responseU.body.data.recipe
expect(recipeNew.title).toBe(fakeRecipeForUpdate.title)
expect(recipeNew.description).toBe(fakeRecipeForUpdate.description)
expect(recipeNew.imageUrl).toBe(fakeRecipeForUpdate.imageUrl)
expect(recipeNew.timeToCook).toBe(fakeRecipeForUpdate.timeToCook)
expect(recipeNew.ingredients).toEqual(fakeRecipeForUpdate.ingredients)
expect(recipeNew.procedure).toEqual(fakeRecipeForUpdate.procedure)
});
});