Skip to content

Commit

Permalink
feat(api): add dependency injection on organizationLearnerRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick committed Oct 8, 2024
1 parent 496c00c commit 1a1cdd0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const getOrganizationLearner = async function ({ organizationLearnerId, organizationLearnerRepository }) {
return organizationLearnerRepository.get(organizationLearnerId);
return organizationLearnerRepository.get({ organizationLearnerId });
};

export { getOrganizationLearner };
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as attestationsApi from '../../../../profile/application/api/attestations-api.js';
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import * as organizationLearnerRepository from './organization-learner-repository.js';

const repositoriesWithoutInjectedDependencies = {
organizationLearnerRepository,
};

const dependencies = {
attestationsApi,
};

const repositories = injectDependencies(repositoriesWithoutInjectedDependencies, dependencies);

export { repositories };
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function _buildIsCertifiable(queryBuilder, organizationLearnerId) {
.where('campaign-participations.deletedAt', null);
}

async function get(organizationLearnerId) {
async function get({ organizationLearnerId }) {
const row = await knex
.with('subquery', (qb) => _buildIsCertifiable(qb, organizationLearnerId))
.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
//given
const randomOrganizationLearnerId = 123;
//when
const err = await catchErr(organizationLearnerRepository.get)(randomOrganizationLearnerId);
const err = await catchErr(organizationLearnerRepository.get)({
organizationLearnerId: randomOrganizationLearnerId,
});
//then
expect(err.message).to.equal(`Student not found for ID ${randomOrganizationLearnerId}`);
expect(err).to.be.an.instanceOf(NotFoundError);
Expand All @@ -37,7 +39,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(1233);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId: 1233 });
expect(organizationLearner.id).to.equal(1233);
expect(organizationLearner.firstName).to.equal('Dark');
expect(organizationLearner.lastName).to.equal('Sasuke');
Expand All @@ -54,7 +56,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun

await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(id);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId: id });

expect(organizationLearner.id).to.equal(id);
});
Expand All @@ -70,7 +72,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.group).to.equal('L3');
expect(organizationLearner.division).to.equal(null);
Expand All @@ -87,7 +89,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.division).to.equal('3B');
expect(organizationLearner.group).to.equal(null);
Expand All @@ -104,7 +106,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.group).to.equal(null);
expect(organizationLearner.division).to.equal(null);
Expand All @@ -119,7 +121,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
const { id: organizationLearnerId } = databaseBuilder.factory.buildOrganizationLearner({ userId });
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.authenticationMethods).to.be.empty;
});
Expand All @@ -133,7 +135,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
const { id: organizationLearnerId } = databaseBuilder.factory.buildOrganizationLearner({ userId });
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.authenticationMethods).to.have.members([
NON_OIDC_IDENTITY_PROVIDERS.PIX.code,
Expand Down Expand Up @@ -167,7 +169,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
await databaseBuilder.commit();

// when
const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

//then
expect(organizationLearner.isCertifiable).to.be.true;
Expand Down Expand Up @@ -200,7 +202,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.be.true;
expect(organizationLearner.certifiableAt).to.deep.equal(certifiableParticipation.sharedAt);
Expand Down Expand Up @@ -242,7 +244,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
await databaseBuilder.commit();

// when
const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

//then
expect(organizationLearner.isCertifiable).to.be.false;
Expand All @@ -263,7 +265,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
await databaseBuilder.commit();

// when
const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

//then
expect(organizationLearner.isCertifiable).to.be.true;
Expand Down Expand Up @@ -293,7 +295,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.be.false;
expect(organizationLearner).to.be.an.instanceOf(OrganizationLearner);
Expand Down Expand Up @@ -321,7 +323,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun

await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.be.null;
expect(organizationLearner.certifiableAt).to.be.null;
Expand All @@ -346,7 +348,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.be.null;
expect(organizationLearner.certifiableAt).to.equal(null);
Expand Down Expand Up @@ -385,7 +387,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun

await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.equal(certifiableParticipation.isCertifiable);
expect(organizationLearner.certifiableAt).to.deep.equal(certifiableParticipation.sharedAt);
Expand Down Expand Up @@ -417,7 +419,7 @@ describe('Integration | Infrastructure | Repository | Organization Learner', fun
});
await databaseBuilder.commit();

const organizationLearner = await organizationLearnerRepository.get(organizationLearnerId);
const organizationLearner = await organizationLearnerRepository.get({ organizationLearnerId });

expect(organizationLearner.isCertifiable).to.equal(notDeletedParticipation.isCertifiable);
expect(organizationLearner.certifiableAt).to.deep.equal(notDeletedParticipation.sharedAt);
Expand Down

0 comments on commit 1a1cdd0

Please sign in to comment.