Files
boc/boc/backend/pdf/document_test.go
T
Bernt 1a12fb870b dev-api: add developer portal, OpenAPI spec, and Flatenbadet case study
- New /developers/ page with API docs, SDKs, pricing, use cases
- OpenAPI 3.0 spec for Orders, Missions, Photos, Analytics
- Case study: Glasskiosken i Flatenbadet — complete ROI analysis
- Updated /order/ with recurring missions and frequency dropdown
2026-07-14 15:27:33 +00:00

76 lines
1.9 KiB
Go

package pdf
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGenerateDocument_Invoice(t *testing.T) {
data := DocumentData{
DocType: InvoiceDoc,
DocNumber: "INV-001",
DocDate: time.Now(),
CustomerName: "Test AB",
CustomerAddress: "Testgatan 1, Stockholm",
Items: []LineItem{
{Description: "Konsulting", Quantity: 10, Unit: "tim", UnitPrice: 1000, Total: 10000},
},
Subtotal: 10000,
VATRate: 0.25,
VATAmount: 2500,
Total: 12500,
Currency: "USD",
CompanyName: "Landvex Inc",
CompanyAddress: "Houston, TX",
Notes: "Betalningsvillkor: 30 dagar",
}
pdfBytes, err := GenerateDocument(data)
require.NoError(t, err)
assert.NotNil(t, pdfBytes)
assert.Greater(t, len(pdfBytes), 1000)
// PDF magic number
assert.Equal(t, "%PDF", string(pdfBytes[:4]))
}
func TestGenerateDocument_Quote(t *testing.T) {
validUntil := time.Now().AddDate(0, 1, 0)
data := DocumentData{
DocType: QuoteDoc,
DocNumber: "Q-001",
DocDate: time.Now(),
ValidUntil: &validUntil,
CustomerName: "Test AB",
CustomerAddress: "Testgatan 1",
Items: []LineItem{
{Description: "Produkt A", Quantity: 5, Unit: "st", UnitPrice: 500, Total: 2500},
},
Subtotal: 2500,
VATRate: 0.25,
VATAmount: 625,
Total: 3125,
Currency: "USD",
CompanyName: "Landvex Inc",
CompanyAddress: "Houston, TX",
}
pdfBytes, err := GenerateDocument(data)
require.NoError(t, err)
assert.NotNil(t, pdfBytes)
assert.Equal(t, "%PDF", string(pdfBytes[:4]))
}
func TestDocInfoLabel(t *testing.T) {
assert.Equal(t, "FAKTURAINFORMATION", docInfoLabel(InvoiceDoc))
assert.Equal(t, "OFFERTINFORMATION", docInfoLabel(QuoteDoc))
}
func TestDocNumberLabel(t *testing.T) {
assert.Equal(t, "Fakturanr", docNumberLabel(InvoiceDoc))
assert.Equal(t, "Offertnr", docNumberLabel(QuoteDoc))
}