49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package invoice
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseMarkdownSample(t *testing.T) {
|
|
file, err := os.Open("../../testdata/sample.md")
|
|
if err != nil {
|
|
t.Fatalf("open sample: %v", err)
|
|
}
|
|
defer file.Close()
|
|
|
|
doc, err := ParseMarkdown(file)
|
|
if err != nil {
|
|
t.Fatalf("ParseMarkdown: %v", err)
|
|
}
|
|
if doc.Seller.Name != "Alice Example" {
|
|
t.Fatalf("seller name mismatch: %q", doc.Seller.Name)
|
|
}
|
|
if doc.Seller.Email != "alice@example.com" {
|
|
t.Fatalf("seller email mismatch: %q", doc.Seller.Email)
|
|
}
|
|
if doc.Seller.Phone != "01 02 03 04 05" {
|
|
t.Fatalf("seller phone mismatch: %q", doc.Seller.Phone)
|
|
}
|
|
if doc.Buyer.Name != "Example Corp" {
|
|
t.Fatalf("buyer name mismatch: %q", doc.Buyer.Name)
|
|
}
|
|
if doc.Invoice.Number != "20250407" {
|
|
t.Fatalf("invoice number mismatch: %q", doc.Invoice.Number)
|
|
}
|
|
if len(doc.Items) != 1 {
|
|
t.Fatalf("expected 1 item, got %d", len(doc.Items))
|
|
}
|
|
if !strings.HasPrefix(doc.Items[0].Designation, "Forfait IT") {
|
|
t.Fatalf("designation mismatch: %q", doc.Items[0].Designation)
|
|
}
|
|
}
|
|
|
|
func TestValidateMissingFields(t *testing.T) {
|
|
doc := Document{}
|
|
if err := Validate(&doc); err == nil {
|
|
t.Fatalf("expected validation error")
|
|
}
|
|
}
|