Skip to content

Commit

Permalink
test(search): upgrade mongoose, use jest and supertest, and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ijemma Onwuzulike authored and Ijemma Onwuzulike committed Oct 27, 2022
1 parent ba5624b commit 231136c
Show file tree
Hide file tree
Showing 29 changed files with 3,324 additions and 1,133 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"env": {
"es2021": true,
"node": true,
"mocha": true
"jest": true
},
"extends": [
"next",
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
timeout-minutes: 3

strategy:
matrix:
Expand All @@ -32,7 +33,7 @@ jobs:
env:
CI: test
- name: Test API
run: yarn mocha
run: yarn jest
env:
CI: test
MAIN_KEY: ${{ secrets.MAIN_KEY }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ dist
# Cypress
./cypress/

# Jest
__tests__/__mocks__/dictionaries/

# Backup directories
./igbo_api_db
./aws_pronunciations
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,5 @@ yarn start:database
in one terminal, and the following in another:

```
yarn mocha
yarn jest
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions __tests__/api-json.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { isEqual } from 'lodash';
import { NO_PROVIDED_TERM } from '../src/shared/constants/errorMessages';
import { searchTerm } from './shared/commands';

describe('JSON Dictionary', () => {
describe('/GET words', () => {
it.skip('should return back word information', async () => {
const keyword = 'agụū';
const res = await searchTerm(keyword);
expect(res.status).toEqual(200);
Object.keys(res.body).forEach((key) => {
expect(['(agụū) -gụ', '-gụ agụū', 'agụū mmīli', keyword]).toContain(key);
});
expect(res.body[keyword][0].wordClass).toEqual('NNC');
});

it('should return an error for searching no word', async () => {
const res = await searchTerm();
expect(res.status).toEqual(400);
expect(res.body.error).toEqual(NO_PROVIDED_TERM);
});

it('should return the same term information', async () => {
const { status, body: normalizeData } = await searchTerm('ndi ndi');
expect(status).toEqual(200);
const { status: rawStatus, body: rawData } = await searchTerm('ndị ndi');
expect(rawStatus).toEqual(200);
expect(isEqual(normalizeData, rawData)).toEqual(true);
});

it('should return term using variation', async () => {
const res = await searchTerm('-mu-mù');
expect(res.status).toEqual(200);
expect(res.body['-mụ-mù']).toHaveLength(1);
});
});
});
Loading

0 comments on commit 231136c

Please sign in to comment.