-
Notifications
You must be signed in to change notification settings - Fork 4
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
kabiribraheem
committed
Jan 23, 2019
1 parent
5f34e63
commit f814271
Showing
8 changed files
with
182 additions
and
52 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
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
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,84 @@ | ||
const { expect } = require('chai'); | ||
const user = require('../../database/models').User; | ||
const { userprofile } = require('../../database/models'); | ||
const article = require('../../lib/modelManagers/articlemodel'); | ||
const constants = require('../mockData'); | ||
|
||
|
||
let id; | ||
let res; | ||
let articleid, article2id; | ||
let testArticle, testArticle2; | ||
describe('Unit test article model manager functions', () => { | ||
before(async () => { | ||
res = await user.create(constants.userdata).then(async (newUser) => { | ||
await userprofile.create(constants.userprofile); | ||
return newUser; | ||
}); | ||
({ id } = res.dataValues); | ||
testArticle = constants.article(id); | ||
testArticle2 = constants.article(id); | ||
article2id = testArticle2.id; | ||
}); | ||
|
||
it('should create a new article when all necesary fields are provided', async () => { | ||
const res = await article.createArticle(testArticle); | ||
articleid = res.dataValues.id; | ||
expect(res).to.be.an('object'); | ||
expect(res.dataValues.isPublished).to.be.equals(false); | ||
expect(res.dataValues.title).to.be.equals(testArticle.title); | ||
expect(res.dataValues.description).to.be.equals(testArticle.description); | ||
expect(res.dataValues.content).to.be.equals(testArticle.content); | ||
expect(res.dataValues.featuredImageUrl).to.be.equals(testArticle.featuredImageUrl); | ||
expect(res.dataValues.averageRating).to.be.equals(testArticle.averageRating); | ||
expect(res.dataValues.authorId).to.be.equals(testArticle.authorId); | ||
expect(res.dataValues.slug).to.be.equals(testArticle.Slug); | ||
expect(res.dataValues.readTime).to.be.equals(testArticle.readTime); | ||
}); | ||
|
||
it('should update an article when update fields are provided and article exists', async () => { | ||
const updatedArticle = constants.updatearticle(id); | ||
const res = await article.updateArticle(updatedArticle, articleid); | ||
const updatedDetails = await article.getallArticlesby('id', articleid); | ||
expect(res).to.be.an('array'); | ||
expect(res[0]).to.be.equals(1); | ||
expect(updatedDetails[0].dataValues.title).to.be.equals(updatedArticle.title); | ||
expect(updatedDetails[0].dataValues.content).to.be.equals(updatedArticle.content); | ||
expect(updatedDetails[0].dataValues.description).to.be.equals(updatedArticle.description); | ||
expect(updatedDetails[0].dataValues.featuredImageUrl) | ||
.to.be.equals(updatedArticle.featuredImageUrl); | ||
expect(updatedDetails[0].dataValues.averageRating).to.be.equals(updatedArticle.averageRating); | ||
expect(updatedDetails[0].dataValues.authorId).to.be.equals(updatedArticle.authorId); | ||
expect(updatedDetails[0].dataValues.slug).to.be.equals(updatedArticle.Slug); | ||
expect(updatedDetails[0].dataValues.readTime).to.be.equals(updatedArticle.readTime); | ||
}); | ||
|
||
it('should get all articles filter by a specific field', async () => { | ||
await article.createArticle(testArticle2); | ||
const res = await article.getallArticlesby('authorId', id); | ||
expect(res.length).to.be.equals(2); | ||
expect(res[0].dataValues.authorId).to.be.equals(id); | ||
}); | ||
|
||
it('should display all articles when no column name is passed', async () => { | ||
const res = await article.getallArticlesby(); | ||
expect(res.length).to.be.equals(2); | ||
}); | ||
|
||
it('should get all articles present in the database with 1 article page pagination', async () => { | ||
const res = await article.getallArticlesby('authorId', id, 1, 0); | ||
expect(res.length).to.be.equals(1); | ||
expect(res[0].dataValues.articleid).to.be.equals(testArticle.articleid); | ||
}); | ||
|
||
it('should display the second article on the second of pagination', async () => { | ||
const res = await article.getallArticlesby('authorId', id, 1, 1); | ||
expect(res.length).to.be.equals(1); | ||
expect(res[0].dataValues.articleid).to.be.equals(article2id); | ||
}); | ||
|
||
it('should delete an article when a valid id is provided', async () => { | ||
const res = await article.deleteArticle(articleid); | ||
expect(res).to.be.equals(1); | ||
}); | ||
}); |
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