Skip to content

Commit

Permalink
fix(api): name job according to controller name
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Sep 23, 2024
1 parent 53c348c commit 7726c4f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const buildOrganizationLearner = function ({
deletedBy = null,
deletedAt = null,
attributes = null,
certifiableAt = null,
isCertifiable = null,
} = {}) {
organizationId = _.isUndefined(organizationId) ? buildOrganization().id : organizationId;
userId = _.isUndefined(userId) ? buildUser().id : userId;
Expand All @@ -32,6 +34,8 @@ const buildOrganizationLearner = function ({
deletedBy,
deletedAt,
attributes,
certifiableAt,
isCertifiable,
};

return databaseBuffer.pushInsertable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { computeCertificabilityJobRepository } from '../../../learner-management

class ScheduleComputeOrganizationLearnersCertificabilityJobController extends JobScheduleController {
constructor() {
super('ComputeOrganizationLearnersCertificabilityJob', {
super('ScheduleComputeOrganizationLearnersCertificabilityJob', {
jobCron: config.features.scheduleComputeOrganizationLearnersCertificability.cron,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as organizationLearnerRepository from '../../../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import { ScheduleComputeOrganizationLearnersCertificabilityJobController } from '../../../../../../src/prescription/learner-management/application/jobs/schedule-compute-organization-learners-certificability-job-controller.js';
import { computeCertificabilityJobRepository } from '../../../../../../src/prescription/learner-management/infrastructure/repositories/jobs/compute-certificability-job-repository.js';
import { ORGANIZATION_FEATURE } from '../../../../../../src/shared/domain/constants.js';
import { databaseBuilder, expect, knex, sinon } from '../../../../../test-helper.js';

describe('Integration | Infrastructure | Jobs | scheduleComputeOrganizationLearnersCertificabilityJobController', function () {
context('#handle', function () {
let logger;

beforeEach(async function () {
const organization = databaseBuilder.factory.buildOrganization();
const feature = databaseBuilder.factory.buildFeature({
key: ORGANIZATION_FEATURE.COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY.key,
});
databaseBuilder.factory.buildOrganizationFeature({ featureId: feature.id, organizationId: organization.id });

databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({
organizationId: organization.id,
certifiabledAt: null,
isCertifiable: null,
});
databaseBuilder.factory.prescription.organizationLearners.buildOrganizationLearner({
organizationId: organization.id,
certifiabledAt: null,
isCertifiable: null,
});

await databaseBuilder.commit();
logger = {
info: sinon.stub(),
};
});

it('should schedule multiple ComputeCertificabilityJob', async function () {
// given
const scheduleComputeOrganizationLearnersCertificabilityJobHandler =
new ScheduleComputeOrganizationLearnersCertificabilityJobController();

// when
await scheduleComputeOrganizationLearnersCertificabilityJobHandler.handle({
data: { skipLoggedLastDayCheck: true, onlyNotComputed: false },
dependencies: {
logger,
organizationLearnerRepository,
computeCertificabilityJobRepository,
config: {
features: {
scheduleComputeOrganizationLearnersCertificability: {
chunkSize: 2,
cron: '0 21 * * *',
},
},
},
},
});
// then

const computeCertificabilityJobs = await knex('pgboss.job').where({ name: 'ComputeCertificabilityJob' });

expect(computeCertificabilityJobs).lengthOf(2);
});
});
});

0 comments on commit 7726c4f

Please sign in to comment.