-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Block the access to the school if the session is not started
- Loading branch information
1 parent
bf60481
commit f0c1377
Showing
8 changed files
with
194 additions
and
2 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
9 changes: 9 additions & 0 deletions
9
api/src/school/application/usecases/is-school-session-active.js
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,9 @@ | ||
import * as schoolRepository from '../../infrastructure/repositories/school-repository.js'; | ||
|
||
const execute = async function ({ schoolCode, dependencies = { schoolRepository } }) { | ||
const result = await dependencies.schoolRepository.getSessionExpirationDate({ code: schoolCode }); | ||
|
||
return result && new Date() < new Date(result) ? true : false; | ||
}; | ||
|
||
export { execute }; |
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
43 changes: 43 additions & 0 deletions
43
api/tests/school/unit/application/usecases/is-school-session-active_test.js
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,43 @@ | ||
import { execute as isSchoolSessionActive } from '../../../../../src/school/application/usecases/is-school-session-active.js'; | ||
import { expect, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Domain | Use Cases | is-session-active', function () { | ||
let clock; | ||
|
||
beforeEach(function () { | ||
const now = new Date('2022-08-04'); | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('should return false if no sessionExpirationDate found for school', async function () { | ||
const dependencies = { schoolRepository: { getSessionExpirationDate: sinon.stub() } }; | ||
dependencies.schoolRepository.getSessionExpirationDate.resolves(undefined); | ||
|
||
const result = await isSchoolSessionActive({ schoolCode: 'CODE1', dependencies }); | ||
|
||
expect(dependencies.schoolRepository.getSessionExpirationDate).to.have.been.calledWithExactly({ code: 'CODE1' }); | ||
expect(result).to.be.false; | ||
}); | ||
|
||
it('should return false if date is passed', async function () { | ||
const dependencies = { schoolRepository: { getSessionExpirationDate: sinon.stub() } }; | ||
dependencies.schoolRepository.getSessionExpirationDate.resolves('2022-07-04T00:00:00.000Z'); | ||
|
||
const result = await isSchoolSessionActive({ schoolCode: 'CODE1', dependencies }); | ||
|
||
expect(result).to.be.false; | ||
}); | ||
|
||
it('should return true if session is still active', async function () { | ||
const dependencies = { schoolRepository: { getSessionExpirationDate: sinon.stub() } }; | ||
dependencies.schoolRepository.getSessionExpirationDate.resolves('2022-08-04T01:00:00.000Z'); | ||
|
||
const result = await isSchoolSessionActive({ schoolCode: 'CODE1', dependencies }); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
}); |
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