73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import { after, before, describe, it } from "node:test";
|
|
import { CreatePauseCancelTaskDTO, PauseCancelTaskRepository } from "./PauseCancelTaskRepository.js";
|
|
import { postgrClient } from "#config/postgreConfig.js";
|
|
import assert from "node:assert";
|
|
|
|
const testTask: CreatePauseCancelTaskDTO = {
|
|
iccid: "1234",
|
|
operation_type: "suspend",
|
|
activation_date: new Date(),
|
|
next_check: new Date(),
|
|
action_data: {
|
|
dueDate: new Date().toString(),
|
|
correlation_id: "12223",
|
|
identifier: {
|
|
identifiers: ["1234"],
|
|
identifierType: "ICCID"
|
|
}
|
|
}
|
|
}
|
|
|
|
describe("Test PauseCancelTaskRepository - DB", () => {
|
|
|
|
const createdIds: number[] = [];
|
|
const pauseRepo = new PauseCancelTaskRepository(postgrClient)
|
|
|
|
before(() => {
|
|
})
|
|
|
|
after(() => {
|
|
})
|
|
|
|
it("Should create a task", async () => {
|
|
const created = await pauseRepo.addTask(testTask)
|
|
assert.ok(created != undefined, "A value must be returned always")
|
|
assert.ok(created.error == undefined, "Should not return a error")
|
|
assert.ok(created.data != undefined, "Data must be returned")
|
|
createdIds.push(created.data.id)
|
|
})
|
|
|
|
it("Should update a existing task", async () => {
|
|
const updated = await pauseRepo.updateTask({
|
|
id: createdIds[0],
|
|
next_check: new Date()
|
|
})
|
|
|
|
assert.ok(updated != undefined, "A value must be returned always")
|
|
assert.ok(updated.error == undefined, "Should not return a error")
|
|
assert.ok(updated.data != undefined, "Data must be returned")
|
|
})
|
|
|
|
it("Should finish a existing task", async () => {
|
|
const finish = await pauseRepo.finishTask({
|
|
id: createdIds[0],
|
|
error: "ok"
|
|
})
|
|
|
|
assert.ok(finish != undefined, "A value must be returned always")
|
|
assert.ok(finish.error == undefined, "Should not return a error")
|
|
assert.ok(finish.data != undefined, "Data must be returned")
|
|
})
|
|
|
|
it("Should get at least 1 pending task", async () => {
|
|
const created = await pauseRepo.addTask(testTask)
|
|
const pending = await pauseRepo.getPending()
|
|
|
|
assert.ok(pending != undefined, "A value must be returned always")
|
|
assert.ok(pending.error == undefined, "Should not return a error")
|
|
assert.ok(pending.data != undefined, "Data must be returned")
|
|
|
|
console.log("--> ", pending.data[0])
|
|
})
|
|
})
|