From 93506a2038d9502b0d2661bb2f308adde41888ff Mon Sep 17 00:00:00 2001 From: AlexBelyan Date: Thu, 4 Jun 2026 15:17:38 +0300 Subject: [PATCH] =?UTF-8?q?12=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=82=D1=80=D0=B0=D0=BD=D0=B7=D0=B0=D0=BA=D1=86=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=B5,=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D1=83=D0=B6?= =?UTF-8?q?=D0=B5=20=D1=81=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D1=8B=D0=B5=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/api/services/receipts_test.go | 23 +++++++++++++++++ .../receiptProvider/receipt_provider_test.go | 19 ++++++++++++++ backend/src/utils/parser_test.go | 25 +++++++++++++++++++ infra/application/Dockerfile | 3 ++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 backend/src/api/services/receipts_test.go create mode 100644 backend/src/integrations/receiptProvider/receipt_provider_test.go create mode 100644 backend/src/utils/parser_test.go diff --git a/backend/src/api/services/receipts_test.go b/backend/src/api/services/receipts_test.go new file mode 100644 index 0000000..59e4177 --- /dev/null +++ b/backend/src/api/services/receipts_test.go @@ -0,0 +1,23 @@ +package services + +import ( + "FamilyHub/src/domain" + "testing" +) + +func TestBuildReceiptTransactionDescription_UsesNameTO(t *testing.T) { + receipt := &domain.Receipt{ + NameSPD: "Old merchant name", + NameTO: "Expected terminal name", + ReceiptNumber: "77F05E82C1ED044B07194794", + } + + description := buildReceiptTransactionDescription(receipt, nil) + if description == nil { + t.Fatal("expected description to be set") + } + + if *description != "Expected terminal name" { + t.Fatalf("expected description %q, got %q", "Expected terminal name", *description) + } +} diff --git a/backend/src/integrations/receiptProvider/receipt_provider_test.go b/backend/src/integrations/receiptProvider/receipt_provider_test.go new file mode 100644 index 0000000..449b7ef --- /dev/null +++ b/backend/src/integrations/receiptProvider/receipt_provider_test.go @@ -0,0 +1,19 @@ +package receiptProvider + +import ( + "strings" + "testing" +) + +func TestBuildMultipartBody_NormalizesDateToISO(t *testing.T) { + body, _ := buildMultipartBody("07.04.2026", "77F05E82C1ED044B07194794") + payload := body.String() + + if !strings.Contains(payload, "2026-04-07") { + t.Fatalf("expected ISO date in multipart body, got %q", payload) + } + + if strings.Contains(payload, "07.04.2026") { + t.Fatalf("did not expect source date format in multipart body, got %q", payload) + } +} diff --git a/backend/src/utils/parser_test.go b/backend/src/utils/parser_test.go new file mode 100644 index 0000000..556ac7c --- /dev/null +++ b/backend/src/utils/parser_test.go @@ -0,0 +1,25 @@ +package utils + +import "testing" + +func TestExtractReceiptMeta_NormalizesOCRDateWithColon(t *testing.T) { + text := "Двойной Американо\n1762992079489\n1,000 x 5,50\n5,50\nИТОГО К ОПЛАТЕ:\n5,50\nБП Карта:\n5,50\nКассир:\nср Кто все эти л\nДата и время:\n07:04.2026 08:57:14\nУИ:\n77F05E82C1ED044B07194794" + + meta := ExtractReceiptMeta(text) + + if meta.Date != "07.04.2026" { + t.Fatalf("expected normalized date %q, got %q", "07.04.2026", meta.Date) + } + + if meta.ReceiptID != "77F05E82C1ED044B07194794" { + t.Fatalf("expected receipt id %q, got %q", "77F05E82C1ED044B07194794", meta.ReceiptID) + } +} + +func TestExtractReceiptMeta_DoesNotTreatTimeAsDate(t *testing.T) { + meta := ExtractReceiptMeta("Дата и время:\n08:57:14\nУИ:\n77F05E82C1ED044B07194794") + + if meta.Date != "" { + t.Fatalf("expected empty date, got %q", meta.Date) + } +} diff --git a/infra/application/Dockerfile b/infra/application/Dockerfile index be8a7df..dc66ec2 100644 --- a/infra/application/Dockerfile +++ b/infra/application/Dockerfile @@ -39,7 +39,8 @@ FROM scratch COPY --from=backend /app/server /server COPY --from=backend /app/migrations /migrations +COPY --from=backend /app/src/api/dist /src/api/dist COPY --from=backend /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=backend /usr/share/zoneinfo /usr/share/zoneinfo -ENTRYPOINT ["/server"] \ No newline at end of file +ENTRYPOINT ["/server"] -- 2.52.0