diff --git a/api/src/prescription/learner-management/application/sup-organization-management-controller.js b/api/src/prescription/learner-management/application/sup-organization-management-controller.js index b270048418a..434c1cc35f1 100644 --- a/api/src/prescription/learner-management/application/sup-organization-management-controller.js +++ b/api/src/prescription/learner-management/application/sup-organization-management-controller.js @@ -13,7 +13,7 @@ const importSupOrganizationLearners = async function ( unlink: fs.unlink, }, ) { - const organizationId = request.params.id; + const organizationId = request.params.organizationId; const userId = request.auth.credentials.userId; try { @@ -51,7 +51,7 @@ const replaceSupOrganizationLearners = async function ( }, ) { const userId = request.auth.credentials.userId; - const organizationId = request.params.id; + const organizationId = request.params.organizationId; try { await usecases.uploadCsvFile({ @@ -82,7 +82,7 @@ const replaceSupOrganizationLearners = async function ( }; const getOrganizationLearnersCsvTemplate = async function (request, h, dependencies = { tokenService }) { - const organizationId = request.params.id; + const organizationId = request.params.organizationId; const token = request.query.accessToken; const userId = dependencies.tokenService.extractUserId(token); const template = await usecases.getOrganizationLearnersCsvTemplate({ @@ -99,7 +99,7 @@ const getOrganizationLearnersCsvTemplate = async function (request, h, dependenc const updateStudentNumber = async function (request, h) { const payload = request.payload.data.attributes; - const organizationId = request.params.id; + const organizationId = request.params.organizationId; const studentNumber = payload['student-number']; const organizationLearnerId = request.params.organizationLearnerId; diff --git a/api/src/prescription/learner-management/application/sup-organization-management-route.js b/api/src/prescription/learner-management/application/sup-organization-management-route.js index cd18c88a10c..e385e1feeff 100644 --- a/api/src/prescription/learner-management/application/sup-organization-management-route.js +++ b/api/src/prescription/learner-management/application/sup-organization-management-route.js @@ -20,7 +20,7 @@ const register = async function (server) { server.route([ { method: 'POST', - path: '/api/organizations/{id}/sup-organization-learners/replace-csv', + path: '/api/organizations/{organizationId}/sup-organization-learners/replace-csv', config: { pre: [ { @@ -30,7 +30,7 @@ const register = async function (server) { ], validate: { params: Joi.object({ - id: identifiersType.organizationId, + organizationId: identifiersType.organizationId, }), }, payload: { @@ -57,7 +57,7 @@ const register = async function (server) { }, { method: 'POST', - path: '/api/organizations/{id}/sup-organization-learners/import-csv', + path: '/api/organizations/{organizationId}/sup-organization-learners/import-csv', config: { pre: [ { @@ -67,7 +67,7 @@ const register = async function (server) { ], validate: { params: Joi.object({ - id: identifiersType.organizationId, + organizationId: identifiersType.organizationId, }), }, payload: { @@ -94,12 +94,12 @@ const register = async function (server) { }, { method: 'GET', - path: '/api/organizations/{id}/organization-learners/csv-template', + path: '/api/organizations/{organizationId}/organization-learners/csv-template', config: { auth: false, validate: { params: Joi.object({ - id: identifiersType.organizationId, + organizationId: identifiersType.organizationId, }), query: Joi.object({ accessToken: Joi.string().required(), @@ -116,7 +116,7 @@ const register = async function (server) { }, { method: 'PATCH', - path: '/api/organizations/{id}/sup-organization-learners/{organizationLearnerId}', + path: '/api/organizations/{organizationId}/sup-organization-learners/{organizationLearnerId}', config: { pre: [ { @@ -129,7 +129,7 @@ const register = async function (server) { allowUnknown: true, }, params: Joi.object({ - id: identifiersType.organizationId, + organizationId: identifiersType.organizationId, organizationLearnerId: identifiersType.organizationLearnerId, }), payload: Joi.object({ diff --git a/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js b/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js index cec34950cc9..4641a718092 100644 --- a/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js @@ -20,7 +20,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le server = await createServer(); }); - describe('POST organizations/:id/sup-organization-learners/import-csv', function () { + describe('POST organizations/{organizationId}/sup-organization-learners/import-csv', function () { let connectedUser; beforeEach(async function () { @@ -130,7 +130,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le ); }); - describe('POST organizations/:id/sup-organization-learners/replace-csv', function () { + describe('POST organizations/{organizationId}/sup-organization-learners/replace-csv', function () { let connectedUser; beforeEach(async function () { @@ -188,7 +188,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le }); }); - describe('GET /api/organizations/{id}/organization-learners/csv-template', function () { + describe('GET /api/organizations/{organizationId}/organization-learners/csv-template', function () { let userId, organization, accessToken; beforeEach(async function () { diff --git a/api/tests/prescription/learner-management/unit/domain/usecases/replace-sup-organization-learners_test.js b/api/tests/prescription/learner-management/unit/domain/usecases/replace-sup-organization-learners_test.js index c3153b16677..ca580b74885 100644 --- a/api/tests/prescription/learner-management/unit/domain/usecases/replace-sup-organization-learners_test.js +++ b/api/tests/prescription/learner-management/unit/domain/usecases/replace-sup-organization-learners_test.js @@ -11,6 +11,7 @@ const supOrganizationLearnerImportHeader = new SupOrganizationLearnerImportHeade .join(';'); describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { + let organizationImportId; const organizationId = 1234; const userId = 333; let organizationImport, @@ -20,7 +21,9 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { expectedLearners; beforeEach(function () { + organizationImportId = Symbol('organizationImportId'); organizationImport = new OrganizationImport({ + id: organizationImportId, filename: 'file.csv', organizationId, createdBy: userId, @@ -28,10 +31,11 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { }); supOrganizationLearnerRepositoryStub = { replaceStudents: sinon.stub().resolves() }; organizationImportRepositoryStub = { - getLastByOrganizationId: sinon.stub().withArgs(organizationId).resolves(organizationImport), + get: sinon.stub(), save: sinon.stub(), }; + organizationImportRepositoryStub.get.withArgs(organizationImportId).resolves(organizationImport); importStorageStub = { readFile: sinon.stub(), deleteFile: sinon.stub(), @@ -84,7 +88,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { // when await replaceSupOrganizationLearners({ - organizationId, + organizationImportId, i18n, supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub, organizationImportRepository: organizationImportRepositoryStub, @@ -110,7 +114,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { // when await replaceSupOrganizationLearners({ - organizationId, + organizationImportId, i18n, supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub, organizationImportRepository: organizationImportRepositoryStub, @@ -134,7 +138,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { // when await replaceSupOrganizationLearners({ - organizationId, + organizationImportId, supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub, importStorage: importStorageStub, organizationImportRepository: organizationImportRepositoryStub, @@ -149,7 +153,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { describe('errors case', function () { beforeEach(function () { - organizationImportRepositoryStub.getLastByOrganizationId.withArgs(organizationId).resolves(organizationImport); + organizationImportRepositoryStub.get.withArgs(organizationImportId).resolves(organizationImport); const csvContent = `${supOrganizationLearnerImportHeader} Beatrix;The;Bride;Kiddo;Black Mamba;01/01/1970;thebride@example.net;123456;Assassination Squad;Hattori Hanzo;Deadly Viper Assassination Squad;BAD;BAD; @@ -165,7 +169,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () { // when await catchErr(replaceSupOrganizationLearners)({ - organizationId, + organizationImportId, i18n, supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub, organizationImportRepository: organizationImportRepositoryStub,