-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests to get-orgs endpoint
- Loading branch information
1 parent
3981726
commit 12822ce
Showing
4 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { pool } from '../src/postgres-setup'; | ||
import { request } from './utils'; | ||
|
||
jest.mock('../src/postgres-setup.ts', () => ({ | ||
pool: { | ||
connect: jest.fn().mockResolvedValue({ | ||
query: jest.fn(), | ||
release: jest.fn(), | ||
}), | ||
}, | ||
})); | ||
|
||
const orgValidatorResponse = { | ||
rows: [ | ||
{ | ||
org_name: 'Paradise Island', | ||
}, | ||
], | ||
}; | ||
|
||
const queryResponse = { | ||
rows: [ | ||
{ | ||
org_name: 'Banana Tree', | ||
relatioship_type: 'daughter', | ||
}, | ||
{ | ||
org_name: 'Big Banana Tree', | ||
relationship_type: 'daughter', | ||
}, | ||
], | ||
}; | ||
|
||
describe('get-organisation', () => { | ||
test.only('should get organization responses for an existing org', async () => { | ||
const client = await pool.connect(); | ||
(client.query as jest.Mock).mockResolvedValueOnce(orgValidatorResponse); | ||
(client.query as jest.Mock).mockResolvedValueOnce(queryResponse); | ||
const result = await request.get('/organisations/Paradise Island'); | ||
expect(result.status).toBe(200); | ||
expect(JSON.stringify(result.body)).toMatch( | ||
JSON.stringify(queryResponse.rows), | ||
); | ||
}); | ||
|
||
test('should not get organization responses for a non existing org', async () => { | ||
const client = await pool.connect(); | ||
(client.query as jest.Mock).mockResolvedValueOnce({ rows: [] }); | ||
(client.query as jest.Mock).mockResolvedValueOnce({ rows: [] }); | ||
const result = await request.get('/organisations/Paradise Island'); | ||
expect(result.status).toBe(404); | ||
// expect(result.body).toMatch("Organisation does not exist") | ||
}); | ||
|
||
test('should not get organization responses for an org without relatives', async () => { | ||
const client = await pool.connect(); | ||
(client.query as jest.Mock).mockResolvedValueOnce({ | ||
rows: [{ org_name: 'Paradise Island' }], | ||
}); | ||
(client.query as jest.Mock).mockResolvedValueOnce({ rows: [] }); | ||
const result = await request.get('/organisations/Paradise Island'); | ||
expect(result.status).toBe(204); | ||
// expect(result.body).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { pool } from '../src/postgres-setup'; | ||
import { request } from './utils'; | ||
|
||
jest.mock('../src/postgres-setup.ts', () => ({ | ||
pool: { | ||
connect: jest.fn().mockResolvedValue({ | ||
query: jest.fn(), | ||
release: jest.fn(), | ||
}), | ||
}, | ||
})); | ||
|
||
describe('App test', () => { | ||
test('Should request base route with success', async () => { | ||
const client = await pool.connect(); | ||
(client.query as jest.Mock).mockResolvedValueOnce({ | ||
rows: [{ org_name: 'example' }], | ||
}); | ||
const result = await request.get('/'); | ||
|
||
expect(result.status).toBe(200); | ||
expect(result.text).toBe('Hello World'); | ||
expect(result.body).toStrictEqual([{ org_name: 'example' }]); | ||
}); | ||
}); |