-
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.
- Loading branch information
1 parent
88c6aa7
commit 462ce6d
Showing
5 changed files
with
67 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
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,47 @@ | ||
import chai, { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { RegionRepository } from '../repositories/region-repository'; | ||
import { getMockDBConnection } from '../__mocks__/db'; | ||
import { RegionService } from './region-service'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('RegionService', () => { | ||
describe('calculateAndAddRegionsForSubmission', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should succeed with valid data', async () => { | ||
const mockDBConnection = getMockDBConnection(); | ||
const service = new RegionService(mockDBConnection); | ||
|
||
const calculate = sinon | ||
.stub(RegionRepository.prototype, 'calculateRegionsForASubmission') | ||
.resolves([{ region_id: 1 }]); | ||
const insert = sinon.stub(RegionRepository.prototype, 'insertSubmissionRegions').resolves(); | ||
|
||
await service.calculateAndAddRegionsForSubmission(1); | ||
|
||
expect(calculate).to.be.called; | ||
expect(insert).to.be.called; | ||
}); | ||
|
||
it('should succeed with modified parameters', async () => { | ||
const mockDBConnection = getMockDBConnection(); | ||
const service = new RegionService(mockDBConnection); | ||
|
||
const calculate = sinon | ||
.stub(RegionRepository.prototype, 'calculateRegionsForASubmission') | ||
.resolves([{ region_id: 1 }]); | ||
const insert = sinon.stub(RegionRepository.prototype, 'insertSubmissionRegions').resolves(); | ||
|
||
await service.calculateAndAddRegionsForSubmission(1, 0.5, 0.5); | ||
|
||
expect(calculate).to.be.calledWith(1, 0.5, 0.5); | ||
expect(insert).to.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