import test, { after, before, describe } from "node:test"; import { CreateObjeniousLineDTO } from "sim-shared/domain/objeniousLine.js"; import { ObjeniousLinesRepository } from "sim-shared/infrastructure/ObjeniousLinesRepository.js"; import assert from "node:assert"; import { postgresClient } from "../config/config.test.js"; describe("Line insertion test", async () => { //const pgClient = postgreClientIntranet const pgClient = postgresClient// En prod hay que usar el de Intrantet para usar la otra base de datos const lineRepository = new ObjeniousLinesRepository(pgClient) const lineaTest: CreateObjeniousLineDTO = { simId: 1234, iccid: "9999999999999", msisdn: "34654674732", imei: "219789481293", imeiChangeDate: new Date(), offerCode: "SAVEFAMILY1", status: "ACTIVATED", preactivationDate: new Date(), activationDate: new Date(), commercialStatus: "test", commercialStatusDate: new Date(), billingStatus: "test", billingStatusChangeDate: new Date(), billingActivationDate: new Date(), createDate: new Date(), raw: { test: "test" } as any // Para este test no hace falta } // Clean up before and after tests to ensure isolation const cleanup = async () => { await pgClient.query("DELETE FROM objenious_lines WHERE simId = 1234"); }; before(async () => { await cleanup() }) after(async () => { await cleanup() }) test("Should insert new line", async () => { const res = await lineRepository.insertOrUpdate(lineaTest) assert.ok(res != undefined, "The line wasn't created") }) test("Should not update a line if the hash is the same", async () => { const res = await lineRepository.insertOrUpdate(lineaTest) assert.ok(res == undefined, "The line have been updated") }) test("Should update a line if the hash changes", async () => { const updated = structuredClone(lineaTest) lineaTest.billingActivationDate = new Date() const res = await lineRepository.insertOrUpdate(lineaTest) assert.ok(res != undefined, "The line have been updated") }) })