From a5e5b4a1147a4f38efefb90b2fcb6cd052e57031 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 20 Nov 2023 19:31:10 +0000 Subject: [PATCH] Extends bulk print invoice spec to assert on file contents --- spec/system/admin/orders_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 8c8b388d63..3582f198e3 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -592,7 +592,18 @@ describe ' perform_enqueued_jobs(only: BulkInvoiceJob) expect(page).to have_content "Bulk Invoice created" - expect(page).to have_link(class: "button", text: "VIEW FILE", href: /invoices/) + + within ".modal-content" do + expect(page).to have_link(class: "button", text: "VIEW FILE", href: /invoices/) + + extract_pdf_content # extracts content do variable invoice_content + + expect(@invoice_content).to have_content("TAX INVOICE", count: 2) + expect(@invoice_content).to have_content("TAX INVOICE: #{order4.number}") + expect(@invoice_content).to have_content("TAX INVOICE: #{order5.number}") + expect(@invoice_content).to have_content("From: #{distributor4.name}") + expect(@invoice_content).to have_content("From: #{distributor5.name}") + end end it "can bulk cancel 2 orders" do @@ -922,3 +933,12 @@ describe ' end end end + +def extract_pdf_content + pdf_href = page.all('a').pluck('href') + page.find(class: "button", text: "VIEW FILE").click + invoice_file_number = pdf_href[0][45..59] + invoice_path = "tmp/invoices/#{invoice_file_number}.pdf" + reader = PDF::Reader.new(invoice_path) + @invoice_content = reader.pages.map(&:text) +end