Skip to content

Commit

Permalink
tech(api): use organizationId instead of id
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car authored Nov 20, 2024
1 parent 2c48960 commit c46bc06
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -30,7 +30,7 @@ const register = async function (server) {
],
validate: {
params: Joi.object({
id: identifiersType.organizationId,
organizationId: identifiersType.organizationId,
}),
},
payload: {
Expand All @@ -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: [
{
Expand All @@ -67,7 +67,7 @@ const register = async function (server) {
],
validate: {
params: Joi.object({
id: identifiersType.organizationId,
organizationId: identifiersType.organizationId,
}),
},
payload: {
Expand All @@ -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(),
Expand All @@ -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: [
{
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const supOrganizationLearnerImportHeader = new SupOrganizationLearnerImportHeade
.join(';');

describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {
let organizationImportId;
const organizationId = 1234;
const userId = 333;
let organizationImport,
Expand All @@ -20,18 +21,21 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {
expectedLearners;

beforeEach(function () {
organizationImportId = Symbol('organizationImportId');
organizationImport = new OrganizationImport({
id: organizationImportId,
filename: 'file.csv',
organizationId,
createdBy: userId,
encoding: 'utf-8',
});
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(),
Expand Down Expand Up @@ -84,7 +88,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {

// when
await replaceSupOrganizationLearners({
organizationId,
organizationImportId,
i18n,
supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub,
organizationImportRepository: organizationImportRepositoryStub,
Expand All @@ -110,7 +114,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {

// when
await replaceSupOrganizationLearners({
organizationId,
organizationImportId,
i18n,
supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub,
organizationImportRepository: organizationImportRepositoryStub,
Expand All @@ -134,7 +138,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {

// when
await replaceSupOrganizationLearners({
organizationId,
organizationImportId,
supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub,
importStorage: importStorageStub,
organizationImportRepository: organizationImportRepositoryStub,
Expand All @@ -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;[email protected];123456;Assassination Squad;Hattori Hanzo;Deadly Viper Assassination Squad;BAD;BAD;
Expand All @@ -165,7 +169,7 @@ describe('Unit | UseCase | ReplaceSupOrganizationLearner', function () {

// when
await catchErr(replaceSupOrganizationLearners)({
organizationId,
organizationImportId,
i18n,
supOrganizationLearnerRepository: supOrganizationLearnerRepositoryStub,
organizationImportRepository: organizationImportRepositoryStub,
Expand Down

0 comments on commit c46bc06

Please sign in to comment.