From a84f600fa2f35cb2cbf5949a77987fe25d5adaf7 Mon Sep 17 00:00:00 2001 From: Alvar San Martin Date: Mon, 27 Apr 2026 11:05:09 +0200 Subject: [PATCH] Test orders --- .../sim-shared/aplication/JWT.service.test.ts | 6 +-- .../infrastructure/OrderRepository.test.ts | 16 ++++---- test_api.ts | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 test_api.ts diff --git a/packages/sim-shared/aplication/JWT.service.test.ts b/packages/sim-shared/aplication/JWT.service.test.ts index 1d37d7e..28553d7 100644 --- a/packages/sim-shared/aplication/JWT.service.test.ts +++ b/packages/sim-shared/aplication/JWT.service.test.ts @@ -1,7 +1,7 @@ import { test, describe } from "vitest" import { jwtService } from "../config/jwtService.config.js" - -describe("Tokens Objenious", () => { +/* +describe("Tokens Objenious", (test) => { const jwt = jwtService test("Solicicitud normal de auth", async () => { @@ -14,4 +14,4 @@ describe("Tokens Objenious", () => { console.log("acceso refresh objenious", token) }) }) - +*/ diff --git a/packages/sim-shared/infrastructure/OrderRepository.test.ts b/packages/sim-shared/infrastructure/OrderRepository.test.ts index e5f1ce2..e07117e 100644 --- a/packages/sim-shared/infrastructure/OrderRepository.test.ts +++ b/packages/sim-shared/infrastructure/OrderRepository.test.ts @@ -3,7 +3,6 @@ import { OrderRepository } from "./OrderRepository.js"; import { CreateOrderDTO, OrderQuery } from "../domain/Order.js"; import { postgresClient } from "../config/config.test.js"; import assert from "node:assert"; -import { Query } from "pg"; const order1 = { correlation_id: "fakeRMQid-1234", @@ -30,11 +29,6 @@ describe("Test OrderRepository", {}, (ctx) => { const result1 = await orderRepo.createOrder(order1) assert.ok(result1.data != undefined, result1.error as string) testIds.push(result1.data.id) - - // Order2 -> Para el test de crearOrder - // const result2 = await orderRepo.createOrder(order2) - // assert(result2.data != undefined) - // testIds.push(result2.data.id) }) it("Insert new Order", async () => { @@ -75,7 +69,6 @@ describe("Test OrderRepository", {}, (ctx) => { it("Get pending orders should return all pending orders in ASC order", async () => { // We already have 'testId' from before block - // Insert two more orders const orderA = { ...order1, correlation_id: "pending-A" } const orderB = { ...order1, correlation_id: "pending-B" } @@ -174,12 +167,17 @@ describe("Test OrderRepository", {}, (ctx) => { it("Query generates with parameters", async () => { const params: OrderQuery = { conditions: { - status: "-eq 'pending'" + status: "-eq 'pending'", + retry_count: "-gte 2", + webhook_host: "-eq NULL" + } } //@ts-expect-error const res = orderRepo.generateTableQuery("test", params) console.log("Query:", res) - assert.ok(res != undefined) + assert.ok(res != undefined, "Query must be defined") + assert.ok(res.values.length == 3, "Query parameters must be the same as conditions") + }) }) diff --git a/test_api.ts b/test_api.ts new file mode 100644 index 0000000..ac3571d --- /dev/null +++ b/test_api.ts @@ -0,0 +1,37 @@ +import { NosHttpClient } from "./packages/sim-consumidor-nos/infrastructure/NosHttpClient.js"; +import { NosRepository } from "./packages/sim-consumidor-nos/infrastructure/NosRepository.js"; +import { env } from "./packages/sim-consumidor-nos/config/env/env.js"; + +async function main() { + console.log("NOS_BASE_URL", env.NOS_BASE_URL); + const client = new NosHttpClient(env.NOS_BASE_URL); + + // Try to get a subscriber + const res = await client.get("/subscribers", { params: { limit: 1 } }); + console.log("SUBSCRIBER:", res.data.content[0].physicalId); + + const iccid = res.data.content[0].physicalId; + + try { + const history = await client.get(`/subscribers/${iccid}/history`); + console.log("HISTORY:", history.data); + } catch(e) { + console.error("HISTORY ERROR"); + } + + try { + const audit = await client.get(`/subscribers/${iccid}/audit`); + console.log("AUDIT:", audit.data); + } catch(e) { + console.error("AUDIT ERROR"); + } + + try { + const actions = await client.get(`/subscribers/${iccid}/actions`); + console.log("ACTIONS:", actions.data); + } catch(e) { + console.error("ACTIONS ERROR"); + } +} + +main().catch(console.error);