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

Adds test for duplicate quotes #510

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/

# Test files
duplicates.json
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ Then run the **demo.js**:
$ node demo.js
```

## Tests

Issue #257

### Duplicate quotes

Duplicate quotes can be found by running:

```
npm run test:duplicates
```

If any duplicate quotes are found, they will be output to a `duplicates.json` file to review. This only looks for duplicate quotes, not authors.

## Related Works

[![Quotter](https://img.shields.io/badge/GitHub%20Repo-Quotter-follow.svg?logo=github&style=social)](https://github.com/vinitshahdeo/Quotter) [![Twitter Follow](https://img.shields.io/twitter/follow/SayHiToQuotter.svg?style=social&logoColor=teal)](https://twitter.com/SayHiToQuotter)
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "A simple NPM Package which returns Inspirational Quotes. Get your daily quote and stay motivated!",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha",
"test:duplicates": "mocha test/duplicates.js"
},
"repository": {
"type": "git",
Expand All @@ -25,6 +26,10 @@
},
"directories": {
"example": "examples",
"data":"data"
"data": "data"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.2.2"
}
}
28 changes: 28 additions & 0 deletions test/duplicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs')
const expect = require('chai').expect;
const inputQuotesJson = require('../data/data.json')

const formatQuote = (quote) => {
return quote.replace(/\W/g, '').toLowerCase().trim();
}

describe('Quotes', () => {
const duplicateQuotes = [];
it('Checks for duplicate quotes', () => {
const quoteSet = new Set();
inputQuotesJson.map(mockQuote => {
let setSize = quoteSet.size;
const formattedQuote = formatQuote(mockQuote.text);
quoteSet.add(formattedQuote);
if(setSize === quoteSet.size) {
duplicateQuotes.push(mockQuote)
}
});

fs.writeFile('duplicates.json', JSON.stringify(duplicateQuotes), 'utf8', (err) => {
if (err) console.log(err)
});

expect(quoteSet.size).to.equal(inputQuotesJson.length);
})
})