Skip to content

Commit

Permalink
Merge pull request #103 from AlexLakatos/update-package
Browse files Browse the repository at this point in the history
Release search functionality for the library
  • Loading branch information
AlexLakatos authored Oct 4, 2021
2 parents 979a5cf + 20e1bb5 commit 9ed3520
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ Returns the pun from the id in the pun list:
}
```

#### `.search`

```JavaScript
puns.search([keyword])
```
Returns a list of puns matching the list of keywords:
```JavaScript
[{
"pun": "Q: How do you comfort a JavaScript bug?",
"punchline": "A: You console it!"
}]
```

## Node.js CLI

TBD
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "puns.dev",
"version": "0.1.5",
"description": "A hand-picked selection of the worst computer puns on the Internet, really cringe worthy stuff.",
"version": "0.2.1",
"description": "A hand-picked selection of the worst computer puns on the Internet, really cringe-worthy stuff.",
"main": "index.js",
"scripts": {
"test": "mocha",
Expand Down
10 changes: 7 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('puns', function () {

describe('#search()', function () {
it('should return a unique list of puns that include a given word', function () {
let searchResults = puns.search("What do you call a group of 8 hobbits");
let searchResults = puns.search(["What do you call a group of 8 hobbits"]);
let pun = {
"pun": "Q: What do you call a group of 8 hobbits?",
"punchline": "A: A hobbyte!"
Expand All @@ -62,12 +62,16 @@ describe('puns', function () {
expect(puns.search("JavaScript").length).to.be.above(0);
});

it('should return all puns when no search keyword is used', function () {
expect(puns.search().length).to.equal(puns.all().length);
});

it('should accept multiple keywords', function () {
expect(puns.search("hobbits", "JavaScript").length).to.not.equal(0);
expect(puns.search(["hobbits", "JavaScript"]).length).to.not.equal(0);
});

it('should return an empty list if no puns are found matching any of the keywords', function () {
expect(puns.search("aabb").length).to.equal(0);
expect(puns.search(["aabb"]).length).to.equal(0);
});
})
});

0 comments on commit 9ed3520

Please sign in to comment.