-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathreceipt_test.go
More file actions
88 lines (74 loc) · 2.17 KB
/
Copy pathreceipt_test.go
File metadata and controls
88 lines (74 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//go:build integration
package appie
import (
"context"
"testing"
)
func TestGetReceiptsIntegration(t *testing.T) {
client := testClient(t)
ctx := context.Background()
receipts, err := client.GetReceipts(ctx)
if err != nil {
t.Fatalf("failed to get receipts: %v", err)
}
t.Logf("Found %d receipts", len(receipts))
for i, r := range receipts {
if i >= 5 {
t.Logf(" ... and %d more", len(receipts)-5)
break
}
t.Logf(" - %s: %s - %.2f EUR", r.TransactionID, r.Date, r.TotalAmount)
}
}
func TestGetReceiptIntegration(t *testing.T) {
client := testClient(t)
ctx := context.Background()
// First get the list to find a valid transaction ID
receipts, err := client.GetReceipts(ctx)
if err != nil {
t.Fatalf("failed to get receipts: %v", err)
}
if len(receipts) == 0 {
t.Skip("no receipts available to test")
}
transactionID := receipts[0].TransactionID
t.Logf("Fetching receipt details for transaction: %s", transactionID)
receipt, err := client.GetReceipt(ctx, transactionID)
if err != nil {
t.Fatalf("failed to get receipt %s: %v", transactionID, err)
}
t.Logf("Receipt: %s", receipt.TransactionID)
t.Logf(" Date: %s", receipt.Date)
t.Logf(" Total: %.2f EUR", receipt.TotalAmount)
t.Logf(" Items: %d", len(receipt.Items))
for i, item := range receipt.Items {
if i >= 5 {
t.Logf(" ... and %d more items", len(receipt.Items)-5)
break
}
t.Logf(" - %s: %.2f EUR (qty: %d) wi=%d", item.Description, item.Amount, item.Quantity, item.WebshopID)
}
var resolved int
for _, item := range receipt.Items {
if item.WebshopID > 0 {
resolved++
}
}
if resolved == 0 {
t.Errorf("expected at least one ReceiptItem to have WebshopID > 0, got 0 of %d", len(receipt.Items))
}
for _, item := range receipt.Items {
if item.WebshopID == 0 {
continue
}
product, err := client.GetProduct(ctx, item.WebshopID)
if err != nil {
t.Fatalf("GetProduct(wi%d) for kassabon line %q: %v", item.WebshopID, item.Description, err)
}
if product.Title == "" {
t.Errorf("GetProduct(wi%d) returned empty title", item.WebshopID)
}
t.Logf(" resolved %d (%s) -> wi%d (%s)", item.ProductID, item.Description, item.WebshopID, product.Title)
break
}
}