Skip to content

Commit

Permalink
[util] unit test for getAllDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Nov 20, 2021
1 parent 3a0ca23 commit b4118e9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/util/__fixtures__/getAllDocs.js
@@ -0,0 +1,11 @@
export default {
'/myindex/doc/bardoc1': {
foo: 'bar',
},
'/myindex/doc/bardoc2': {
foo: 'bar',
},
'/myindex/doc/notbar': {
foo: 'something else',
},
};
30 changes: 30 additions & 0 deletions src/util/__tests__/getAllDocs.js
@@ -0,0 +1,30 @@
import { loadFixtures, unloadFixtures } from 'util/fixtures';
import fixtures from '../__fixtures__/getAllDocs';
import getAllDocs from '../getAllDocs';

beforeAll(async () => {
await loadFixtures(fixtures);
});

afterAll(() => unloadFixtures(fixtures));

it('fetches all docs in the index by default', async () => {
const ids = [];
for await (const { _id } of getAllDocs('myindex')) {
ids.push(_id);
}

expect(ids).toEqual(expect.arrayContaining(['bardoc1', 'bardoc2', 'notbar']));
});

it('fetches only the doc that matches the query', async () => {
const ids = [];
for await (const { _id } of getAllDocs('myindex', {
term: { foo: 'bar' },
})) {
ids.push(_id);
}

expect(ids).toEqual(expect.arrayContaining(['bardoc1', 'bardoc2']));
expect(ids).not.toEqual(expect.arrayContaining(['notbar']));
});

0 comments on commit b4118e9

Please sign in to comment.