-
Notifications
You must be signed in to change notification settings - Fork 5
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
11 changed files
with
272 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,37 +1,73 @@ | ||
import 'chai/register-should'; | ||
import { expect } from 'chai'; | ||
import { validateArticle } from '../../src/utils/article'; | ||
import { ARTICLE } from '../mock/article'; | ||
import { generateDummyWords } from '../../src/utils'; | ||
import { validateArticle, computeArticleReadingTime } from '../../src/utils/article'; | ||
import {ARTICLE} from '../mock/article'; | ||
|
||
describe('validateArticle()', () => { | ||
it('should return true if the validation passes', async () => { | ||
const validate = await validateArticle(ARTICLE); | ||
expect(validate.passes()).to.be.equal(true); | ||
}); | ||
|
||
it('should return false if the validation fails due to missing field', async () => { | ||
delete ARTICLE.title; | ||
const validate = await validateArticle(ARTICLE); | ||
expect(validate.fails()).to.be.equal(true); | ||
expect(validate.passes()).to.be.equal(false); | ||
describe('Article Utils test', () => { | ||
describe('validateArticle()', () => { | ||
it('should return true if the validation passes', () => { | ||
const validate = validateArticle(ARTICLE); | ||
validate.then((res) => { | ||
expect(res.passes()).to.be.equal(true); | ||
}); | ||
}); | ||
|
||
it('should return false if the validation fails due to missing field', () => { | ||
delete ARTICLE.title; | ||
const validate = validateArticle(ARTICLE); | ||
validate.then((res) => { | ||
expect(res.fails()).to.be.equal(true); | ||
expect(res.passes()).to.be.equal(false); | ||
|
||
const error = res.errors.all(); | ||
expect(error).should.be.an('object'); | ||
expect(error).to.have.property('title'); | ||
expect(error.title).to.be.an('array'); | ||
}); | ||
}); | ||
|
||
it('should return false if the validation fails due to an invalid field', () => { | ||
ARTICLE.title = 1111111111; | ||
ARTICLE.tags = 1111111111; | ||
const validate = validateArticle(ARTICLE); | ||
validate.then((res) => { | ||
expect(res.fails()).to.be.equal(true); | ||
expect(res.passes()).to.be.equal(false); | ||
|
||
const error = validate.errors.all(); | ||
expect(error).should.be.an('object'); | ||
expect(error).to.have.property('title'); | ||
expect(error.title).to.be.an('array'); | ||
const error = res.errors.all(); | ||
expect(error).should.be.an('object'); | ||
expect(error).to.have.property('title'); | ||
expect(error.title).to.be.an('array'); | ||
expect(error.tags).to.be.an('array'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should return false if the validation fails due to an invalid field', async () => { | ||
ARTICLE.title = 1111111111; | ||
ARTICLE.tags = 1111111111; | ||
const validate = await validateArticle(ARTICLE); | ||
expect(validate.fails()).to.be.equal(true); | ||
expect(validate.passes()).to.be.equal(false); | ||
|
||
const error = validate.errors.all(); | ||
expect(error).should.be.an('object'); | ||
expect(error).to.have.property('title'); | ||
expect(error.title).to.be.an('array'); | ||
expect(error.tags).to.be.an('array'); | ||
describe('computeArticleReadingTime()', () => { | ||
describe('handle valid input', () => { | ||
it('should return an estimated reading time', () => { | ||
computeArticleReadingTime('code till you drop!').should.equal(1); | ||
}); | ||
|
||
it('should return an estimated reading time', () => { | ||
computeArticleReadingTime(generateDummyWords('nodejs', 1000)).should.equal(4); | ||
}); | ||
|
||
it('should return an estimated reading time', () => { | ||
computeArticleReadingTime(generateDummyWords('code', 500)).should.equal(2); | ||
}); | ||
}); | ||
|
||
describe('handle invalid input', () => { | ||
it('should throw an error if words is not a string', () => { | ||
(() => computeArticleReadingTime(1)).should.throw(TypeError); | ||
}); | ||
|
||
it('should throw an error if wordsPerMinute is less than 1', () => { | ||
(() => computeArticleReadingTime(generateDummyWords('grit'), { wordsPerMinute: 0 })).should.throw(); | ||
}); | ||
}); | ||
}); | ||
}); |
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