From ec520c330a17257a3b3979118b908c8862cd9f87 Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Tue, 18 Mar 2025 09:27:34 +0100 Subject: [PATCH] fix receipts one --- backend/src/controllers/receipts.c | 1 + backend/src/models/models.c | 10 +++++----- backend/test/test.ts | 12 ++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/src/controllers/receipts.c b/backend/src/controllers/receipts.c index 58dc240..38b1d49 100644 --- a/backend/src/controllers/receipts.c +++ b/backend/src/controllers/receipts.c @@ -59,6 +59,7 @@ void route_get_receipts_one(HttpCtx* ctx) .product_id = products.data[i].id, .name = str_dup(products.data[i].name), .price_dkk_cent = product_prices.data[i].price_dkk_cent, + .amount = receipt.products.data[i].amount, }); } diff --git a/backend/src/models/models.c b/backend/src/models/models.c index d3766a3..83a03ca 100644 --- a/backend/src/models/models.c +++ b/backend/src/models/models.c @@ -310,10 +310,10 @@ char* receipts_one_res_product_to_json_string(const ReceiptsOneResProduct* m) string_construct(&string); string_pushf(&string, "{" - "\"product_id\":\"%ld\"," + "\"product_id\":%ld," "\"name\":\"%s\"," - "\"price_dkk_cent\":\"%ld\"," - "\"price_dkk_cent\":\"%ld\"" + "\"price_dkk_cent\":%ld," + "\"amount\":%ld" "}", m->product_id, m->name, @@ -333,9 +333,9 @@ char* receipts_one_res_to_json_string(const ReceiptsOneRes* m) string_construct(&string); string_pushf(&string, "{" - "\"receipt_id\":\"%ld\"," + "\"receipt_id\":%ld," "\"timestamp\":\"%s\"," - "\"products:\":[", + "\"products\":[", m->receipt_id, m->timestamp); diff --git a/backend/test/test.ts b/backend/test/test.ts index de907e9..0b80856 100644 --- a/backend/test/test.ts +++ b/backend/test/test.ts @@ -107,13 +107,21 @@ async function testCartsAndReceipts(t: Deno.TestContext, token: string) { }); await t.step("test /api/receipts/all", async () => { - const res = await get<{ ok: boolean }>( + const res = await get<{ + ok: boolean; + receipts: { timestamp: string }[]; + }>( `/api/receipts/all`, { "Session-Token": token }, ); - console.log(res); + // console.log(res); assertEquals(res.ok, true); + assertEquals(res.receipts.length, 1); + assertMatch( + res.receipts[0].timestamp, + /\d{4}-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d/, + ); }); }