@sidequest/backend-test
Version:
@sidequest/backend-test is a test suite for backend implementations of Sidequest, a Node.js library for managing background jobs and distributed queues.
56 lines (51 loc) • 2.19 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vitest = require('vitest');
var backend = require('./backend.cjs');
function defineGetJobTestSuite() {
vitest.describe("getJob", () => {
vitest.it("should get no job", async () => {
const job = await backend.backend.getJob(-1);
expect(job).toBeFalsy();
});
vitest.it("should get a job", async () => {
// Insert a waiting job
const job = {
queue: "default",
class: "TestJob",
args: [],
constructor_args: [],
state: "waiting",
script: "test.js",
attempt: 0,
};
const insertedJob = await backend.backend.createNewJob(job);
const foundJob = await backend.backend.getJob(insertedJob.id);
expect(foundJob).toBeTruthy();
expect(foundJob?.errors).toBe(null);
expect(foundJob?.args).toMatchObject([]);
expect(foundJob?.constructor_args).toMatchObject([]);
});
vitest.it("should get a job with errors and args", async () => {
// Insert a waiting job
const job = {
queue: "default",
class: "TestJob",
args: [{ test: true }],
constructor_args: [{ test: true }],
state: "waiting",
script: "test.js",
attempt: 0,
};
const insertedJob = await backend.backend.createNewJob(job);
await backend.backend.updateJob({ ...insertedJob, errors: [{ message: "test", attempt_by: "test-runner" }] });
const foundJob = await backend.backend.getJob(insertedJob.id);
expect(foundJob).toBeTruthy();
expect(foundJob?.errors).toMatchObject([{ message: "test", attempt_by: "test-runner" }]);
expect(foundJob?.args).toMatchObject([{ test: true }]);
expect(foundJob?.constructor_args).toMatchObject([{ test: true }]);
});
});
}
exports.default = defineGetJobTestSuite;
//# sourceMappingURL=getJob.cjs.map