-
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.
[FEATURE] Autoriser l'accès à Pix Junior seulement si une session est…
… active #9456
- Loading branch information
Showing
13 changed files
with
217 additions
and
4 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
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
import * as schoolRepository from '../../infrastructure/repositories/school-repository.js'; | ||
|
||
const execute = async function ({ schoolCode, dependencies = { schoolRepository } }) { | ||
const sessionExpirationDate = await dependencies.schoolRepository.getSessionExpirationDate({ code: schoolCode }); | ||
|
||
return _isSessionActive(sessionExpirationDate); | ||
}; | ||
|
||
function _isSessionActive(sessionExpirationDate) { | ||
return new Date() < new Date(sessionExpirationDate); | ||
} | ||
|
||
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 session is expired', 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
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,14 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
import { styleToolkit } from '../utils/layout'; | ||
|
||
export default class SchoolErrorRoute extends Route { | ||
setupController() { | ||
super.setupController(...arguments); | ||
this.resetBackground(); | ||
} | ||
|
||
resetBackground() { | ||
styleToolkit.backgroundBlob.reset(); | ||
} | ||
} |
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,2 @@ | ||
{{! Cette page est affichée lorsqu'on souhaite aller sur une URL qui n'existe pas coté front }} | ||
<Issue @message={{t "pages.school.not-found"}} /> |
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