Skip to content

Commit fa49646

Browse files
committed
resurrect unit tests
1 parent c78ce18 commit fa49646

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
source: crates/core-invoice/tests/typst_conversion.rs
3+
assertion_line: 36
4+
expression: typst
5+
---
6+
#let provide() = {
7+
(
8+
client: (
9+
company_name: "Holmes Ltd",
10+
contact_person: "Sherlock Holmes",
11+
organisation_number: "9876543-2101",
12+
postal_address: (
13+
city: "London",
14+
country: "England",
15+
street_address: (
16+
line_1: "221B Baker Street",
17+
line_2: "",
18+
),
19+
zip: "NW1 6XE",
20+
),
21+
vat_number: "GB987654321",
22+
),
23+
information: (
24+
due_date: "2025-06-30",
25+
emphasize_color_hex: "#8b008b",
26+
footer_text: "Billed with the utmost discretion—your secrets are safe, for a price.",
27+
invoice_date: "2025-05-31",
28+
number: 34,
29+
purchase_order: "PO-12345",
30+
),
31+
line_items: (
32+
is_expenses: true,
33+
items: (
34+
(
35+
currency: "EUR",
36+
name: "Breakfast",
37+
quantity: 1.0,
38+
total_cost: 1602.25,
39+
transaction_date: "2025-05-20",
40+
unit_price: 1602.25,
41+
),
42+
),
43+
),
44+
output_path: (
45+
name: "2025-05-31_Lupin_et_Associés_expenses_invoice_34.pdf",
46+
),
47+
payment_info: (
48+
bank_name: "Banque de Paris",
49+
bic: "BNPAFRPP",
50+
currency: "EUR",
51+
iban: "FR76 3000 6000 0112 3456 7890 189",
52+
terms: "Net 30",
53+
),
54+
vendor: (
55+
company_name: "Lupin et Associés",
56+
contact_person: "Arsène Lupin",
57+
organisation_number: "7418529-3012",
58+
postal_address: (
59+
city: "Paris",
60+
country: "France",
61+
street_address: (
62+
line_1: "5 Avenue Henri-Martin",
63+
line_2: "Appartement 24",
64+
),
65+
zip: "75116",
66+
),
67+
vat_number: "FR74185293012",
68+
),
69+
)
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
source: crates/core-invoice/tests/typst_conversion.rs
3+
assertion_line: 53
4+
expression: typst
5+
---
6+
#let provide() = {
7+
(
8+
client: (
9+
company_name: "Holmes Ltd",
10+
contact_person: "Sherlock Holmes",
11+
organisation_number: "9876543-2101",
12+
postal_address: (
13+
city: "London",
14+
country: "England",
15+
street_address: (
16+
line_1: "221B Baker Street",
17+
line_2: "",
18+
),
19+
zip: "NW1 6XE",
20+
),
21+
vat_number: "GB987654321",
22+
),
23+
information: (
24+
due_date: "2025-06-30",
25+
emphasize_color_hex: "#8b008b",
26+
footer_text: "Billed with the utmost discretion—your secrets are safe, for a price.",
27+
invoice_date: "2025-05-31",
28+
number: 33,
29+
purchase_order: "PO-12345",
30+
),
31+
line_items: (
32+
is_expenses: false,
33+
items: (
34+
(
35+
currency: "EUR",
36+
name: "Discreet Investigative Services",
37+
quantity: 23.0,
38+
total_cost: 17871.0,
39+
transaction_date: "2025-05-31",
40+
unit_price: 777.0,
41+
),
42+
),
43+
),
44+
output_path: (
45+
name: "2025-05-31_Lupin_et_Associés_invoice_33.pdf",
46+
),
47+
payment_info: (
48+
bank_name: "Banque de Paris",
49+
bic: "BNPAFRPP",
50+
currency: "EUR",
51+
iban: "FR76 3000 6000 0112 3456 7890 189",
52+
terms: "Net 30",
53+
),
54+
vendor: (
55+
company_name: "Lupin et Associés",
56+
contact_person: "Arsène Lupin",
57+
organisation_number: "7418529-3012",
58+
postal_address: (
59+
city: "Paris",
60+
country: "France",
61+
street_address: (
62+
line_1: "5 Avenue Henri-Martin",
63+
line_2: "Appartement 24",
64+
),
65+
zip: "75116",
66+
),
67+
vat_number: "FR74185293012",
68+
),
69+
)
70+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
source: crates/core-invoice/tests/typst_conversion.rs
3+
assertion_line: 62
4+
expression: typst
5+
---
6+
#let provide() = {
7+
(
8+
client_info: (
9+
to_company: "To:",
10+
vat_number: "VAT:",
11+
),
12+
invoice_info: (
13+
client_contact: "For the attention of:",
14+
due_date: "Due date:",
15+
invoice_date: "Invoice date:",
16+
invoice_identifier: "Invoice no:",
17+
purchase_order: "Purchase order:",
18+
terms: "Terms:",
19+
vendor_contact: "Our reference:",
20+
),
21+
line_items: (
22+
description: "Item",
23+
grand_total: "Grand Total:",
24+
quantity: "Quantity",
25+
total_cost: "Total cost",
26+
unit_price: "Unit price",
27+
when: "When",
28+
),
29+
month_names: (
30+
"January",
31+
"February",
32+
"March",
33+
"April",
34+
"May",
35+
"June",
36+
"July",
37+
"August",
38+
"September",
39+
"October",
40+
"November",
41+
"December",
42+
),
43+
vendor_info: (
44+
address: "Address",
45+
bank: "Bank",
46+
bic: "BIC",
47+
iban: "IBAN",
48+
organisation_number: "Org. No.",
49+
vat_number: "VAT No.",
50+
),
51+
)
52+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use insta::assert_snapshot;
2+
use klirr_core_invoice::prelude::*;
3+
4+
fn sample_exchange_rates() -> ExchangeRates {
5+
ExchangeRates::builder()
6+
.target_currency(Currency::EUR)
7+
.rates(ExchangeRatesMap::from_iter([
8+
(Currency::GBP, UnitPrice::from(dec!(1.174))),
9+
(Currency::SEK, UnitPrice::from(dec!(11.05))),
10+
]))
11+
.build()
12+
}
13+
14+
fn prepared_data_from(input: ValidInput) -> PreparedData {
15+
Data::<YearAndMonth>::sample()
16+
.to_partial(input)
17+
.unwrap()
18+
.to_typst(sample_exchange_rates())
19+
.unwrap()
20+
}
21+
22+
#[test]
23+
fn data_expenses_to_typst() {
24+
let input = ValidInput::builder()
25+
.items(InvoicedItems::Expenses)
26+
.period(
27+
YearMonthAndFortnight::builder()
28+
.year(2025.into())
29+
.month(Month::May)
30+
.half(MonthHalf::First)
31+
.build(),
32+
)
33+
.language(Language::EN)
34+
.build();
35+
let typst = prepared_data_from(input).to_typst_fn();
36+
assert_snapshot!("data_expenses_to_typst", typst);
37+
}
38+
39+
#[test]
40+
fn data_services_to_typst() {
41+
let input = ValidInput::builder()
42+
.items(InvoicedItems::Service { time_off: None })
43+
.period(
44+
YearMonthAndFortnight::builder()
45+
.year(2025.into())
46+
.month(Month::May)
47+
.half(MonthHalf::First)
48+
.build(),
49+
)
50+
.language(Language::EN)
51+
.build();
52+
let typst = prepared_data_from(input).to_typst_fn();
53+
assert_snapshot!("data_services_to_typst", typst);
54+
}
55+
56+
#[test]
57+
fn l18n_english_to_typst() {
58+
let typst = L18n::new(Language::EN).unwrap().content().to_typst_fn();
59+
assert_snapshot!("l18n_english_to_typst", typst);
60+
}

0 commit comments

Comments
 (0)