77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package order
|
|
|
|
import "testing"
|
|
|
|
func TestCreatedRoundTrip(t *testing.T) {
|
|
in := Created{
|
|
OrderID: "ord-1",
|
|
OrderReference: "REF-1",
|
|
CartID: "cart-9",
|
|
Country: "se",
|
|
Currency: "SEK",
|
|
CustomerEmail: "a@b.c",
|
|
Lines: []Line{{SKU: "ABC", Quantity: 2, Location: "store-7"}, {SKU: "DEF", Quantity: 1}},
|
|
PlacedAtMs: 123,
|
|
}
|
|
raw, err := in.Encode()
|
|
if err != nil {
|
|
t.Fatalf("encode: %v", err)
|
|
}
|
|
out, err := Decode(raw)
|
|
if err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if out.OrderID != in.OrderID || out.Country != in.Country || len(out.Lines) != 2 {
|
|
t.Fatalf("round-trip mismatch: got %+v, want %+v", out, in)
|
|
}
|
|
if out.Lines[0].SKU != "ABC" || out.Lines[0].Quantity != 2 || out.Lines[0].Location != "store-7" {
|
|
t.Errorf("line[0] mismatch: %+v", out.Lines[0])
|
|
}
|
|
}
|
|
|
|
func TestInvoiceIssuedRoundTrip(t *testing.T) {
|
|
in := InvoiceIssued{
|
|
OrderID: "ord-1",
|
|
InvoiceNumber: "INV-000001",
|
|
CompanyID: "comp-1",
|
|
CustomerEmail: "a@b.c",
|
|
AmountIncVat: 14995,
|
|
DueDate: "2026-09-15",
|
|
OCRReference: "00000139",
|
|
IssuedAtMs: 1234567890,
|
|
}
|
|
raw, err := in.Encode()
|
|
if err != nil {
|
|
t.Fatalf("encode: %v", err)
|
|
}
|
|
out, err := DecodeInvoiceIssued(raw)
|
|
if err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if out.InvoiceNumber != in.InvoiceNumber || out.OCRReference != in.OCRReference || out.AmountIncVat != in.AmountIncVat {
|
|
t.Fatalf("round-trip mismatch: got %+v, want %+v", out, in)
|
|
}
|
|
}
|
|
|
|
func TestInvoicePaidRoundTrip(t *testing.T) {
|
|
in := InvoicePaid{
|
|
OrderID: "ord-1",
|
|
InvoiceNumber: "INV-000001",
|
|
CompanyID: "comp-1",
|
|
AmountPaid: 14995,
|
|
PaidAtMs: 1234567990,
|
|
}
|
|
raw, err := in.Encode()
|
|
if err != nil {
|
|
t.Fatalf("encode: %v", err)
|
|
}
|
|
out, err := DecodeInvoicePaid(raw)
|
|
if err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if out.InvoiceNumber != in.InvoiceNumber || out.AmountPaid != in.AmountPaid {
|
|
t.Fatalf("round-trip mismatch: got %+v, want %+v", out, in)
|
|
}
|
|
}
|
|
|