Skip to content

Commit

Permalink
docs: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeIbberson committed Jan 23, 2020
1 parent b15dd2e commit c6da7cd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install, lint, and test
- name: yarn install, build, and test
run: |
yarn install
yarn lint
yarn test
- name: Coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<h1>🔎 Mongoose partial search plugin</h1>

<p>
<img src="https://github.com/MikeIbberson/mongoose-partial-search/workflows/Node%20CI/badge.svg" alt="Status" />
</p>
<a href='https://coveralls.io/github/MikeIbberson/mongoose-partial-search?branch=master'><img src='https://coveralls.io/repos/github/MikeIbberson/mongoose-partial-search/badge.svg?branch=master' alt='Coverage Status' /></a>
<img src='https://bettercodehub.com/edge/badge/MikeIbberson/mongoose-partial-search?branch=master'>
</p>

<p>This packages adds a <code>searchBuilder</code> static method to the <a href="https://mongoosejs.com/docs/schematypes.html">Mongoose</a> model that returns a case-insensitive, regex-powered query to drop into your find functions.</p>


Expand Down
35 changes: 31 additions & 4 deletions lib/search.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,32 @@ const base = new mongoose.Schema({
},
});

const variant = new mongoose.Schema({
colour: {
type: String,
searchable: true,
},
});

mongoose.plugin(plugin);

const SearchableModel = mongoose.model(
'SearchIntegration',
base,
);

const SearchableModelDiscriminator = SearchableModel.discriminator(
'SearchIntegrationD',
variant,
);

const performSearchQuery = (
term,
expectedResultsLength,
) => (done) =>
SearchableModel.find(SearchableModel.searchBuilder(term))
SearchableModelDiscriminator.find(
SearchableModelDiscriminator.searchBuilder(term),
)
.then((resp) => {
return expect(resp).toHaveLength(
expectedResultsLength,
Expand All @@ -45,13 +59,21 @@ const performSearchQuery = (

beforeAll(async () => {
await mongoose.connect(process.env.CONNECTION);
await SearchableModel.create([
await SearchableModelDiscriminator.create([
{ name: 'John Katie' },
{ name: 'Mary Anne', pet: { name: 'Sniffles' } },
{ name: 'John Kodie', pet: { name: 'Boots' } },
{
name: 'Mary Anne',
pet: { name: 'Sniffles' },
},
{
name: 'John Kodie',
pet: { name: 'Boots' },
colour: 'Green',
},
{
name: 'Henry Boyd',
friends: [{ name: 'Arnold' }, { name: 'Katie' }],
colour: 'Green',
},
]);
});
Expand Down Expand Up @@ -87,4 +109,9 @@ describe('Search', () => {
'should yield match on combined string on multiple fields',
performSearchQuery('John Katie', 1),
);

it(
'should yield match on discriminated value',
performSearchQuery('green', 2),
);
});

0 comments on commit c6da7cd

Please sign in to comment.