Skip to content

Commit

Permalink
fix(server): jobEvents unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenfares committed Jun 1, 2022
1 parent 2a3f57c commit 9722fb1
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions server/tests/integration/common/components/jobEvents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require("assert").strict;
const jobEvents = require("../../../../src/common/components/jobEvents");
const { JobEventModel } = require("../../../../src/common/model");
const { jobEventStatuts } = require("../../../../src/common/constants/jobsConstants");
const { wait } = require("../../../utils/testUtils");
const { addMinutes } = require("date-fns");

describe(__filename, () => {
it("Permet de vérifier si le job courant est dans l'action terminée", async () => {
Expand All @@ -16,27 +16,22 @@ describe(__filename, () => {
date: new Date(),
}).save();

// leave a tiny amount of time, otherwise the jobEvent date field will have the millisecond and test will result in a false-negative
await wait(1);

// Add executed event
await new JobEventModel({
jobname: testJobName,
action: jobEventStatuts.executed,
date: new Date(),
date: addMinutes(new Date(), 5),
}).save();

await wait(1);

// Add ended event
await new JobEventModel({
jobname: testJobName,
action: jobEventStatuts.ended,
date: new Date(),
date: addMinutes(new Date(), 6),
}).save();

const isEnded = await isJobInAction(testJobName, jobEventStatuts.ended);
assert.equal(isEnded, false);
assert.equal(isEnded, true);
});

it("Permet de vérifier si le job courant n'est pas dans l'action terminée", async () => {
Expand All @@ -54,7 +49,7 @@ describe(__filename, () => {
await new JobEventModel({
jobname: testJobName,
action: jobEventStatuts.executed,
date: new Date(),
date: addMinutes(new Date(), 5),
}).save();

const isEnded = await isJobInAction(testJobName, jobEventStatuts.ended);
Expand Down

0 comments on commit 9722fb1

Please sign in to comment.