-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
388 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import './favorite.spec'; | ||
import './recipes.spec'; | ||
import './users.spec'; | ||
import './vote.spec'; | ||
import './models/user.spec'; | ||
import './models/recipe.spec'; | ||
import './models/vote.spec'; | ||
import './models/favorite.spec'; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import models from '../../models'; | ||
|
||
const { Favorite } = models; | ||
|
||
describe('Favorite model', () => { | ||
describe('Create favorites', () => { | ||
it('Should create user favorite', (done) => { | ||
Favorite.create({ | ||
}).then((recipe) => { | ||
expect(recipe).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { expect } from 'chai'; | ||
import models from '../../models'; | ||
|
||
const { Recipe } = models; | ||
|
||
describe('Recipe models', () => { | ||
describe('Create recipe', () => { | ||
it('should fail to create a recipe if no recipe name if provided', (done) => { | ||
Recipe.create({ | ||
description: 'Best recipe in town', | ||
imageUrl: 'http://someimagehere', | ||
category: 'Lunch', | ||
ingredients: 'New baby\nNew recipe', | ||
instructions: 'Make it shine\nLet it shine' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('name cannot be null'); | ||
expect(error.errors[0].type).to.equal('notNull Violation'); | ||
done(); | ||
}); | ||
}); | ||
it('should fail to create a recipe if no category is picked', (done) => { | ||
Recipe.create({ | ||
name: 'My recipe', | ||
description: 'Best recipe in town', | ||
imageUrl: 'http://someimagehere', | ||
ingredients: 'New baby\nNew recipe', | ||
instructions: 'Make it shine\nLet it shine' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('category cannot be null'); | ||
expect(error.errors[0].type).to.equal('notNull Violation'); | ||
done(); | ||
}); | ||
}); | ||
it('Should create a recipe succesfully', (done) => { | ||
Recipe.create({ | ||
name: 'Amazing recipe', | ||
description: 'Amazing recipe description', | ||
imageUrl: 'http://someimagehere', | ||
category: 'Dessert', | ||
ingredients: 'New baby\nNew recipe', | ||
instructions: 'Make it shine\nLet it shine' | ||
}).then((recipe) => { | ||
expect(recipe.dataValues.name).to.be.a('string'); | ||
expect(recipe.dataValues.description).to.be.a('string'); | ||
expect(recipe.dataValues.imageUrl).to.be.a('string'); | ||
expect(recipe.dataValues.category).to.be.a('string'); | ||
expect(recipe.dataValues.ingredients).to.be.a('string'); | ||
expect(recipe.dataValues.instructions).to.be.a('string'); | ||
expect(recipe.dataValues).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('Get all recipes', () => { | ||
it('Should get all the recipes in the application', (done) => { | ||
Recipe.all() | ||
.then((recipes) => { | ||
expect(recipes).to.be.an('array'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('Edit a recipe', () => { | ||
it('Should modify a recipe', (done) => { | ||
Recipe.findById(2) | ||
.then((recipe) => { | ||
recipe.update({ | ||
name: 'Amazing recipe here' | ||
}).then((updatedRecipe) => { | ||
expect(updatedRecipe.dataValues.name) | ||
.to.equal('Amazing recipe here'); | ||
expect(updatedRecipe.dataValues).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('Delete a recipe', () => { | ||
it('Should delete a recipe', (done) => { | ||
Recipe.findById(2) | ||
.then((recipe) => { | ||
recipe.destroy() | ||
.then((deletedRecipe) => { | ||
expect(deletedRecipe.length).to.equal(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect } from 'chai'; | ||
import models from '../../models'; | ||
|
||
const { Review } = models; | ||
|
||
describe('Review model', () => { | ||
describe('Create reviews', () => { | ||
it('should create a new review', (done) => { | ||
Review.create({ | ||
content: 'Amazing recipe man!' | ||
}).then((review) => { | ||
expect(review).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { expect } from 'chai'; | ||
import models from '../../models'; | ||
|
||
const { User } = models; | ||
|
||
describe('User model', () => { | ||
describe('Create User', () => { | ||
it( | ||
'should throw an error if no username is provided when during creation', | ||
(done) => { | ||
User.create({ | ||
email: 'somerandom@gmail.com', | ||
password: 'qwertyuiop' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('username cannot be null'); | ||
expect(error.errors[0].type === 'notNull Violation'); | ||
done(); | ||
}); | ||
} | ||
); | ||
it('should throw an error if no password is provided', (done) => { | ||
User.create({ | ||
username: 'anyrandomname', | ||
email: 'anyrandomemail@gmail.com' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('password cannot be null'); | ||
expect(error.errors[0].type).to.equal('notNull Violation'); | ||
done(); | ||
}); | ||
}); | ||
it('it should throw an error if password length is less than 8', (done) => { | ||
User.create({ | ||
username: 'brandnew', | ||
email: 'brandnew@gmail.com', | ||
password: 'qwer' | ||
}).catch((error) => { | ||
expect(error.errors[0].message) | ||
.to.equal('Enter a password greater than 8 characters'); | ||
expect(error.errors[0].type).to.equal('Validation error'); | ||
done(); | ||
}); | ||
}); | ||
it('Should throw an error if the email is of an invalid format', (done) => { | ||
User.create({ | ||
username: 'william', | ||
email: 'williamgates', | ||
password: 'qwertyuiop' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to | ||
.equal('Validation isEmail on email failed'); | ||
expect(error.errors[0].type).to.equal('Validation error'); | ||
expect(error.errors[0].value).to.equal('williamgates'); | ||
done(); | ||
}); | ||
}); | ||
it('should create a user if all information is valid', (done) => { | ||
User.create({ | ||
username: 'williamsshakespear', | ||
email: 'williamsshakespear@gmail.com', | ||
password: 'qwertyuiop' | ||
}).then((user) => { | ||
expect(user.dataValues.username).to.be.a('string'); | ||
expect(user.dataValues.email).to.be.a('string'); | ||
expect(user.dataValues.password).to.be.a('string'); | ||
expect(user.dataValues.username).to.equal('williamsshakespear'); | ||
expect(user.dataValues.email).to.equal('williamsshakespear@gmail.com'); | ||
expect(user.dataValues.password).to.equal('qwertyuiop'); | ||
done(); | ||
}); | ||
}); | ||
it('should throw an error if the username already exists', (done) => { | ||
User.create({ | ||
username: 'williamsshakespear', | ||
email: 'quantity@gmail.com', | ||
password: 'qwertyuiop' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('username must be unique'); | ||
expect(error.errors[0].type).to.equal('unique violation'); | ||
expect(error.errors[0].value).to.equal('williamsshakespear'); | ||
done(); | ||
}); | ||
}); | ||
it('Should throw an error if the email already exists', (done) => { | ||
User.create({ | ||
username: 'zxcvbnmasd', | ||
email: 'williamsshakespear@gmail.com', | ||
password: 'qwertyuiop' | ||
}).catch((error) => { | ||
expect(error.errors[0].message).to.equal('email must be unique'); | ||
expect(error.errors[0].type).to.equal('unique violation'); | ||
expect(error.errors[0].value).to.equal('williamsshakespear@gmail.com'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from 'chai'; | ||
import models from '../../models'; | ||
|
||
const { Vote } = models; | ||
|
||
describe('Votes model', () => { | ||
describe('Create votes', () => { | ||
it('Should create a vote for a recipe', (done) => { | ||
Vote.create({ | ||
userId: 3, | ||
voteType: 'upvote' | ||
}).then((vote) => { | ||
expect(vote.dataValues).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expect } from 'chai'; | ||
import validateRecipe from '../../validators/validateRecipe'; | ||
|
||
const inputData = { | ||
name: 'Fried rice', | ||
description: 'Amazing recipe', | ||
category: 'Lunch', | ||
ingredients: 'Baking powder\nSoda', | ||
instructions: 'Soda powder\nNomencleture' | ||
}; | ||
|
||
describe('Validate Add recipe', () => { | ||
it('Should throw an error if no name is provided on recipe creation', () => { | ||
const noName = { ...inputData, name: '' }; | ||
const invalidData = validateRecipe(noName); | ||
expect(invalidData.errors.name).to.equal('Recipe name is required'); | ||
}); | ||
it('Should throw an error if no description is passed', () => { | ||
const noDescription = { ...inputData, description: '' }; | ||
const invalidData = validateRecipe(noDescription); | ||
expect(invalidData.errors.description).to | ||
.equal('Enter a description for your recipe'); | ||
}); | ||
it('should throw an error if no category is provided', () => { | ||
const noCategory = { ...inputData, category: '' }; | ||
const invalidData = validateRecipe(noCategory); | ||
expect(invalidData.errors.category).to | ||
.equal('Select a category from the dropdown'); | ||
}); | ||
it('Should throw an error if no ingredient is passed through', () => { | ||
const noIngredient = { ...inputData, ingredients: '' }; | ||
const invalidData = validateRecipe(noIngredient); | ||
expect(invalidData.errors.ingredients).to | ||
.equal('Input some ingredients for your recipe'); | ||
}); | ||
it('Should throw an error if no instruction is provided', () => { | ||
const noInstruction = { ...inputData, instructions: '' }; | ||
const invalidData = validateRecipe(noInstruction); | ||
expect(invalidData.errors.instructions) | ||
.to.equal('Input directions on how to cook your recipe'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from 'chai'; | ||
import validatesignin from '../../validators/validatesignin'; | ||
|
||
const helper = validatesignin; | ||
|
||
describe('Validate signin function', () => { | ||
it('should return an error if no email is passed in the data', () => { | ||
const data = { | ||
password: 'qwertyuiop' | ||
}; | ||
const invalidInput = validatesignin(data); | ||
expect(invalidInput.errors.email).to | ||
.equal('Input an email address to sign-in.'); | ||
}); | ||
it('should return an error if no password is passed in', () => { | ||
const data = { | ||
email: 'qwertyuiop@gmail.com' | ||
}; | ||
const invalidInput = validatesignin(data); | ||
expect(invalidInput.errors.password).to | ||
.equal('Input a password to sign-in.'); | ||
}); | ||
}); |
Oops, something went wrong.