Test para todo el repositorio de orders

This commit is contained in:
2026-02-17 09:33:51 +01:00
parent 39a2622cb1
commit 5d3465fd97
2 changed files with 122 additions and 25 deletions

View File

@@ -41,7 +41,7 @@ export class OrderRepository {
data: queryResult.rows
}
} catch (e) {
return <Result<string, T>>{
return <Result<string, T[]>>{
error: e as string
}
}
@@ -57,7 +57,7 @@ export class OrderRepository {
`
const values = [data.id]
const queryPromise = this.pgClient.query<OrderTracking<any>>(query, values)
const result = this.getFirst(queryPromise);
const result = await this.getFirst(queryPromise);
return result
}
@@ -71,7 +71,7 @@ export class OrderRepository {
`
const values = [data.correlation_id]
const queryPromise = this.pgClient.query<OrderTracking<any>>(query, values)
const result = this.getFirst(queryPromise);
const result = await this.getFirst(queryPromise);
return result
}
@@ -161,7 +161,7 @@ export class OrderRepository {
const uOrderTracking = `
UPDATE order_tracking
SET
status = $2,
status = $2::order_status,
update_date = (now() at time zone 'utc')
WHERE id = $1
RETURNING id, status, update_date;
@@ -188,19 +188,20 @@ export class OrderRepository {
VALUES (
$1, -- ID de la orden
$2, -- Estado anterior
$3, -- Nuevo estado
$3::order_status, -- Nuevo estado
$4 -- Razón (ej: "Consumer processed successfully" o "RabbitMQ NACK")
);
)
RETURNING id;
`
const vOrderHistory = [args.id, currentOrder.status, args.new_status, args.reason]
const newOrderHistory = await this.getFirst(
client.query<{ id: number, status: string, update_date: string }>(iOrderHistory, vOrderHistory)
const newOrderHistoryResult = await this.getFirst(
client.query<{ id: number }>(iOrderHistory, vOrderHistory)
)
if (newOrderHistory.error != undefined) {
if (newOrderHistoryResult.error != undefined) {
await client.query("ROLLBACK")
client.release()
return updatedOrderResult
return newOrderHistoryResult
}
await client.query("COMMIT")
@@ -209,6 +210,7 @@ export class OrderRepository {
client.query<OrderTracking<any>>(qCurrentOrder, vCurrentOrder)
)
client.release()
return updatedOrder
}
@@ -268,17 +270,18 @@ export class OrderRepository {
$2, -- Estado anterior
'finished',
$3 -- Siempre "finished successfully" a no ser que se especifique otra razón
);
)
RETURNING id;
`
const vOrderHistory = [args.id, currentOrder.status, args.reason ?? "finished successfully"]
const newOrderHistory = await this.getFirst(
client.query<{ id: number, status: string, update_date: string }>(iOrderHistory, vOrderHistory)
const newOrderHistoryResult = await this.getFirst(
client.query<{ id: number }>(iOrderHistory, vOrderHistory)
)
if (newOrderHistory.error != undefined) {
if (newOrderHistoryResult.error != undefined) {
await client.query("ROLLBACK")
client.release()
return updatedOrderResult
return newOrderHistoryResult
}
await client.query("COMMIT")
@@ -287,6 +290,7 @@ export class OrderRepository {
client.query<OrderTracking<any>>(qCurrentOrder, vCurrentOrder)
)
client.release()
return updatedOrder
}
@@ -323,9 +327,9 @@ export class OrderRepository {
const uOrderTracking = `
UPDATE order_tracking
SET
status = $2,
status = $2::order_status,
update_date = (now() at time zone 'utc'),
finish_date = CASE WHEN $2 = 'dlx' THEN (now() at time zone 'utc') ELSE null,
finish_date = CASE WHEN $2::order_status = 'dlx' THEN (now() at time zone 'utc') ELSE null END,
retry_count = retry_count + 1,
error_message = $3,
error_stacktrace = $4
@@ -354,19 +358,20 @@ export class OrderRepository {
VALUES (
$1, -- ID de la orden
$2, -- Estado anterior
$3, -- En este caso particular 'dlx' o 'failed'
$3::order_status, -- En este caso particular 'dlx' o 'failed'
$4 -- En este caso el motivo de fallo completo
);
)
RETURNING id;
`
const vOrderHistory = [args.id, currentOrder.status, args.reason ?? "finished successfully", args.stackTrace]
const newOrderHistory = await this.getFirst(
client.query<{ id: number, status: string, update_date: string }>(iOrderHistory, vOrderHistory)
const vOrderHistory = [args.id, currentOrder.status, args.status, args.reason]
const newOrderHistoryResult = await this.getFirst(
client.query<{ id: number }>(iOrderHistory, vOrderHistory)
)
if (newOrderHistory.error != undefined) {
if (newOrderHistoryResult.error != undefined) {
await client.query("ROLLBACK")
client.release()
return updatedOrderResult
return newOrderHistoryResult
}
await client.query("COMMIT")
@@ -375,6 +380,7 @@ export class OrderRepository {
client.query<OrderTracking<any>>(qCurrentOrder, vCurrentOrder)
)
client.release()
return updatedOrder
}