|
1 | 1 | require 'test_helper' |
2 | 2 | require 'date' |
| 3 | +require 'base64' |
3 | 4 |
|
4 | 5 | module Secretariat |
5 | 6 | class InvoiceTest < Minitest::Test |
@@ -55,6 +56,63 @@ def make_eu_invoice |
55 | 56 | ) |
56 | 57 | end |
57 | 58 |
|
| 59 | + def make_eu_invoice_with_attachment |
| 60 | + seller = TradeParty.new( |
| 61 | + name: 'Depfu inc', |
| 62 | + street1: 'Quickbornstr. 46', |
| 63 | + city: 'Hamburg', |
| 64 | + postal_code: '20253', |
| 65 | + country_id: 'DE', |
| 66 | + vat_id: 'DE304755032' |
| 67 | + ) |
| 68 | + buyer = TradeParty.new( |
| 69 | + name: 'Depfu inc', |
| 70 | + street1: 'Quickbornstr. 46', |
| 71 | + city: 'Hamburg', |
| 72 | + postal_code: '20253', |
| 73 | + country_id: 'SE', |
| 74 | + vat_id: 'SE304755032' |
| 75 | + ) |
| 76 | + line_item = LineItem.new( |
| 77 | + name: 'Depfu Starter Plan', |
| 78 | + quantity: 1, |
| 79 | + gross_amount: '29', |
| 80 | + net_amount: '29', |
| 81 | + unit: :PIECE, |
| 82 | + charge_amount: '29', |
| 83 | + tax_category: :REVERSECHARGE, |
| 84 | + tax_percent: 0, |
| 85 | + tax_amount: "0", |
| 86 | + origin_country_code: 'DE', |
| 87 | + currency_code: 'EUR' |
| 88 | + ) |
| 89 | + attachment = Attachment.new( |
| 90 | + filename: 'example.pdf', |
| 91 | + type_code: 916, |
| 92 | + base64: Base64.encode64(open(File.join(__dir__, 'fixtures/example.pdf')).read) |
| 93 | + ) |
| 94 | + Invoice.new( |
| 95 | + id: '12345', |
| 96 | + issue_date: Date.today, |
| 97 | + service_period_start: Date.today, |
| 98 | + service_period_end: Date.today + 30, |
| 99 | + seller: seller, |
| 100 | + buyer: buyer, |
| 101 | + line_items: [line_item], |
| 102 | + currency_code: 'USD', |
| 103 | + payment_type: :CREDITCARD, |
| 104 | + payment_text: 'Kreditkarte', |
| 105 | + tax_category: :REVERSECHARGE, |
| 106 | + tax_amount: '0', |
| 107 | + basis_amount: '29', |
| 108 | + grand_total_amount: 29, |
| 109 | + due_amount: 0, |
| 110 | + paid_amount: 29, |
| 111 | + payment_due_date: Date.today + 14, |
| 112 | + attachments: [attachment] |
| 113 | + ) |
| 114 | + end |
| 115 | + |
58 | 116 | def make_de_invoice |
59 | 117 | seller = TradeParty.new( |
60 | 118 | name: 'Depfu inc', |
@@ -225,6 +283,19 @@ def test_simple_eu_invoice_against_schematron |
225 | 283 | assert_equal [], errors |
226 | 284 | end |
227 | 285 |
|
| 286 | + def test_simple_eu_invoice_with_attachment_against_schematron |
| 287 | + xml = make_eu_invoice_with_attachment.to_xml(version: 2) |
| 288 | + v = Validator.new(xml, version: 2) |
| 289 | + errors = v.validate_against_schematron |
| 290 | + if !errors.empty? |
| 291 | + puts xml |
| 292 | + errors.each do |error| |
| 293 | + puts "#{error}" |
| 294 | + end |
| 295 | + end |
| 296 | + assert_equal [], errors |
| 297 | + end |
| 298 | + |
228 | 299 | def test_simple_de_invoice_v2 |
229 | 300 | xml = make_de_invoice.to_xml(version: 2) |
230 | 301 | v = Validator.new(xml, version: 2) |
|
0 commit comments