-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed various tests, added region repo test
- Loading branch information
1 parent
29b4ce8
commit 88c6aa7
Showing
8 changed files
with
93 additions
and
89 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
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,56 @@ | ||
import chai, { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import { QueryResult } from 'pg'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { getMockDBConnection } from '../__mocks__/db'; | ||
import { RegionRepository } from './region-repository'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('RegionRepository', () => { | ||
describe('getRegions', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('returns an array of region records', async () => { | ||
const mockQueryResponse = { rowCount: 1, rows: [{ region_id: 1 }] } as any as Promise<QueryResult<any>>; | ||
const connection = getMockDBConnection({ | ||
sql: () => mockQueryResponse | ||
}); | ||
|
||
const repo = new RegionRepository(connection); | ||
|
||
const regions = await repo.getRegions(); | ||
expect(regions.length).to.greaterThanOrEqual(1); | ||
}); | ||
}); | ||
|
||
describe('calculateRegionsForASubmission', () => { | ||
it('should succeed without issue', async () => { | ||
const mockQueryResponse = { rowCount: 1, rows: [{ region_id: 1 }] } as any as Promise<QueryResult<any>>; | ||
const connection = getMockDBConnection({ | ||
sql: () => mockQueryResponse | ||
}); | ||
const repo = new RegionRepository(connection); | ||
|
||
const regions = await repo.calculateRegionsForASubmission(1); | ||
|
||
expect(regions).to.be.eql([{ region_id: 1 }]); | ||
}); | ||
}); | ||
|
||
describe('insertSubmissionRegions', () => { | ||
it('should return early with no regions', async () => { | ||
const connection = getMockDBConnection({ | ||
sql: sinon.mock() | ||
}); | ||
|
||
const repo = new RegionRepository(connection); | ||
await repo.insertSubmissionRegions(1, []); | ||
|
||
expect(connection.sql).to.not.be.called; | ||
}); | ||
}); | ||
}); |
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