-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ajouter un endpoint pour récuperer les statistiques par com…
- Loading branch information
Showing
12 changed files
with
236 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
api/src/prescription/organization-learner/application/organization-learners-route.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
5 changes: 5 additions & 0 deletions
5
api/src/prescription/organization-learner/domain/usecases/get-analysis-by-tubes.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,5 @@ | ||
const getAnalysisByTubes = async function ({ organizationId, analysisRepository }) { | ||
return analysisRepository.findByTubes({ organizationId }); | ||
}; | ||
|
||
export { getAnalysisByTubes }; |
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
12 changes: 12 additions & 0 deletions
12
api/src/prescription/organization-learner/infrastructure/repositories/analysis-repository.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,12 @@ | ||
import { config } from '../../../../shared/config.js'; | ||
|
||
async function findByTubes({ organizationId, apiDataDatasource }) { | ||
return apiDataDatasource.get(config.apiData.queries.coverRateByTubes, [ | ||
{ | ||
name: 'organization_id', | ||
value: organizationId, | ||
}, | ||
]); | ||
} | ||
|
||
export { findByTubes }; |
4 changes: 4 additions & 0 deletions
4
api/src/prescription/organization-learner/infrastructure/repositories/index.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
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
32 changes: 32 additions & 0 deletions
32
.../organization-learner/integration/infrastructure/repositories/analysis-repository_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,32 @@ | ||
import * as analysisRepository from '../../../../../../src/prescription/organization-learner/infrastructure/repositories/analysis-repository.js'; | ||
import { config } from '../../../../../../src/shared/config.js'; | ||
import { expect, sinon } from '../../../../../test-helper.js'; | ||
|
||
describe('Integration | Infrastructure | Repository | Analysis', function () { | ||
describe('#findByTubes', function () { | ||
context('when they work properly', function () { | ||
it('should call api data and return it', async function () { | ||
const organizationId = Symbol('organization-id'); | ||
const apiDataDatasource = { | ||
get: sinon.stub(), | ||
}; | ||
|
||
sinon.stub(config, 'apiData').value({ | ||
queries: { | ||
coverRateByTubes: Symbol('cover-query-id'), | ||
}, | ||
}); | ||
|
||
const queryId = config.apiData.queries.coverRateByTubes; | ||
const params = [{ name: 'organization_id', value: organizationId }]; | ||
|
||
const expectedData = Symbol('api-data-result'); | ||
apiDataDatasource.get.withArgs(queryId, params).resolves(expectedData); | ||
|
||
const result = await analysisRepository.findByTubes({ organizationId, apiDataDatasource }); | ||
|
||
expect(result).to.equal(expectedData); | ||
}); | ||
}); | ||
}); | ||
}); |
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
42 changes: 42 additions & 0 deletions
42
...ts/prescription/organization-learner/unit/application/organization-learners-route_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,42 @@ | ||
import { organizationLearnersController } from '../../../../../src/prescription/organization-learner/application/organization-learners-controller.js'; | ||
import * as moduleUnderTest from '../../../../../src/prescription/organization-learner/application/organization-learners-route.js'; | ||
import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; | ||
import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants.js'; | ||
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Prescription | Unit | Router | organization-learner-router', function () { | ||
describe('GET /api/organizations/{organizationId}/organization-learners-level-by-tubes', function () { | ||
const method = 'GET'; | ||
|
||
it('should verify user privilege and organization feature access', async function () { | ||
// given | ||
sinon | ||
.stub(organizationLearnersController, 'getAnalysisByTubes') | ||
.callsFake((request, h) => h.response('ok').code(200)); | ||
sinon.stub(securityPreHandlers, 'checkUserIsAdminInOrganization').callsFake((request, h) => h.response(true)); | ||
sinon | ||
.stub(securityPreHandlers, 'makeCheckOrganizationHasFeature') | ||
.callsFake(() => (request, h) => h.response(true)); | ||
|
||
const httpTestServer = new HttpTestServer(); | ||
await httpTestServer.register(moduleUnderTest); | ||
|
||
const url = '/api/organizations/123/organization-learners-level-by-tubes'; | ||
|
||
// when | ||
const response = await httpTestServer.request(method, url); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(200); | ||
expect(securityPreHandlers.checkUserIsAdminInOrganization).to.have.been.calledBefore( | ||
organizationLearnersController.getAnalysisByTubes, | ||
); | ||
expect(securityPreHandlers.makeCheckOrganizationHasFeature).calledWithExactly( | ||
ORGANIZATION_FEATURE.COVER_RATE.key, | ||
); | ||
expect(securityPreHandlers.makeCheckOrganizationHasFeature).to.have.been.calledBefore( | ||
organizationLearnersController.getAnalysisByTubes, | ||
); | ||
}); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
...ests/prescription/organization-learner/unit/domain/usecases/get-analysis-by-tubes_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,24 @@ | ||
import { getAnalysisByTubes } from '../../../../../../src/prescription/organization-learner/domain/usecases/get-analysis-by-tubes.js'; | ||
import { expect, sinon } from '../../../../../test-helper.js'; | ||
|
||
describe('Unit | UseCase | get-analysis-by-tubes', function () { | ||
it('should call findByTubes method from analysis repository', async function () { | ||
// given | ||
const organizationId = Symbol('organizationId'); | ||
const expectedRepositoryResult = Symbol('expectedRepositoryResult'); | ||
const analysisRepository = { | ||
findByTubes: sinon.stub(), | ||
}; | ||
|
||
analysisRepository.findByTubes.withArgs({ organizationId }).resolves(expectedRepositoryResult); | ||
|
||
// when | ||
await getAnalysisByTubes({ | ||
organizationId, | ||
analysisRepository, | ||
}); | ||
|
||
// then | ||
expect(analysisRepository.findByTubes).to.have.been.called; | ||
}); | ||
}); |