Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test to avoid duplicate Quotes #2278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@
"text":"I’m not afraid of dying, I’m afraid of not trying.",
"from":"Jay Z, musician."
},
{
"text":"Whatever the mind can conceive and believe, the mind can achieve.",
"from":"Dr. Napoleon Hill, author of Think and Grow Rich."
},
{
"text":"The longer you’re not taking action the more money you’re losing",
"from":"Carrie Wilkerson"
Expand Down Expand Up @@ -499,10 +495,6 @@
"text":"Failure defeats losers, failure inspires winners.",
"from":"Robert T. Kiyosaki"
},
{
"text":"I have not failed. I’ve just found 10,000 ways that won’t work.",
"from":"Thomas Edison"
},
{
"text":"The biggest failure you can have in life is not trying at all.",
"from":"Emil Motycka"
Expand Down Expand Up @@ -679,10 +671,6 @@
"text":"If you’re not making mistakes, then you’re not making decisions.",
"from":"Catherine Cook"
},
{
"text":"Your most unhappy customers are your greatest source of learning.",
"from":"Bill Gates"
},
{
"text":"One can get anything if he is willing to help enough others get what they want.",
"from":"Zig Ziglar"
Expand Down Expand Up @@ -939,10 +927,6 @@
"text":"A man must be big enough to admit his mistakes, smart enough to profit from them, and strong enough to correct them.",
"from":"John C. Maxwell"
},
{
"text":"In the modern world of business, it is useless to be a creative, original thinker unless you can also sell what you create.",
"from":"David Ogilvy"
},
{
"text":"Success is doing what you want, where you want, when you want, with whom you want as much as you want.",
"from":"Tony Robbins"
Expand Down
110 changes: 69 additions & 41 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,74 @@
const expect = require('chai').expect,
{ getQuote, getRandomQuote } = require('../lib/index');
{ getQuote, getRandomQuote } = require('../lib/index');

allQuotes = require('../data/data.json');

describe('Running tests for methods of inspirational-quotes', () => {
describe('getQuote', () => {
it('should return an object', (done) => {
const randomQuote = getQuote();
expect(randomQuote).to.be.an('object');
done();
});
it('should contain text and author', (done) => {
const randomQuote = getQuote();
expect(randomQuote).to.have.property('author');
expect(randomQuote).to.have.property('text');
done();
});
it('should not contain empty text', (done) => {
const randomQuote = getQuote();
expect(randomQuote.text).to.not.be.empty;
done();
});
it('should not contain empty author', (done) => {
const randomQuote = getQuote();
expect(randomQuote.author).to.not.be.empty;
done();
});
it('should not return author field if author: false is passed', (done) => {
const randomQuote = getQuote({author: false});
expect(randomQuote).to.not.have.property('author');
expect(randomQuote).to.have.property('text');
done();
});
});
describe('getRandomQuote', () => {
it('should return a string', (done) => {
const randomQuote = getRandomQuote();
expect(randomQuote).to.be.an('string');
done();
});
it('should have length greater than 5', (done) => {
const randomQuote = getRandomQuote();
expect(randomQuote).to.have.length.greaterThan(5);
done();
});
describe('getQuote', () => {
it('should return an object', (done) => {
const randomQuote = getQuote();
expect(randomQuote).to.be.an('object');
done();
});
it('should contain text and author', (done) => {
const randomQuote = getQuote();
expect(randomQuote).to.have.property('author');
expect(randomQuote).to.have.property('text');
done();
});
it('should not contain empty text', (done) => {
const randomQuote = getQuote();
expect(randomQuote.text).to.not.be.empty;
done();
});
it('should not contain empty author', (done) => {
const randomQuote = getQuote();
expect(randomQuote.author).to.not.be.empty;
done();
});
it('should not return author field if author: false is passed', (done) => {
const randomQuote = getQuote({ author: false });
expect(randomQuote).to.not.have.property('author');
expect(randomQuote).to.have.property('text');
done();
});
});
describe('getRandomQuote', () => {
it('should return a string', (done) => {
const randomQuote = getRandomQuote();
expect(randomQuote).to.be.an('string');
done();
});
it('should have length greater than 5', (done) => {
const randomQuote = getRandomQuote();
expect(randomQuote).to.have.length.greaterThan(5);
done();
});
});
describe('data.json', () => {
it('should not have any duplicate quotes', (done) => {
let duplicates = [
...allQuotes
.reduce((accumulator, current) => {
let text = current.text;
accumulator.set(text, (accumulator.get(text) || 0) + 1);
return accumulator;
}, new Map())
.entries(),
]
.filter(([_, occurance]) => occurance > 1)
.map(([text, occurance]) => ({
text,
occurance,
}));

if(duplicates.length>0){
console.log(duplicates);
}

const hasDuplicates = duplicates.length > 0;
expect(hasDuplicates).to.be.false;
done();
});
});
});