Move invoices specs to the invoices spec file

The orders file is too big and causes a bottleneck for parallelising specs.

Maybe they should be merged with the above specs, but I'm not familiar enough to know for sure.
This commit is contained in:
David Cook
2024-05-21 14:32:11 +10:00
parent b729ec3428
commit 39f1eac300
2 changed files with 175 additions and 161 deletions

View File

@@ -1140,165 +1140,4 @@ RSpec.describe '
end
end
end
describe "Legal Invoices", feature: :invoices do
before do
login_as user
end
describe "for order states" do
context "complete" do
let!(:order1) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'complete',
payment_state: 'balance_due',
customer_id: customer.id)
}
context "editing the order" do
before do
visit spree.edit_admin_order_path(order1)
end
it "displays the invoice tab" do
expect(page).to have_content "Complete".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "visiting the invoices tab" do
let!(:table_header) {
[
"Date/Time",
"Invoice Number",
"Amount",
"Status",
"File",
].join(" ").upcase
}
let(:invoice_number){ "#{order.distributor_id}-1" }
let(:table_contents) {
[
Invoice.first.created_at.strftime('%B %d, %Y').to_s,
invoice_number,
"0.0",
"Active",
"Download"
].join(" ")
}
let(:download_href) {
"#{spree.print_admin_order_path(order1)}?invoice_id=#{Invoice.last.id}"
}
before do
Spree::Config[:enterprise_number_required_on_invoices?] = false
visit spree.admin_order_invoices_path(order1)
end
it "displays the invoices table" do
# with no invoices, only the table header is displayed
expect(page).to have_css "table.index"
expect(page).to have_content "#{customer.first_name} #{customer.last_name} -"
expect(page.find("table").text).to have_content(table_header)
# the New invoice button + the warning should be visible
expect(page).to have_link "Create or Update Invoice"
expect(page).to have_content "The order has changed since the last invoice update."
click_link "Create or Update Invoice"
# and disappear after clicking
expect(page).not_to have_link "Create or Update Invoice"
expect(page).not_to have_content "The order has changed since the last invoice update."
# creating an invoice, displays a second row
expect(page.find("table").text).to have_content(table_contents)
# with a valid invoice download link
expect(page).to have_link("Download",
href: download_href)
end
context "the Create or Update Invoice button" do
context "when an ABN number is mandatory for invoices but not present" do
before do
Spree::Config[:enterprise_number_required_on_invoices?] = true
end
it "displays a warning that an ABN is required when it's clicked" do
visit spree.admin_order_invoices_path(order1)
message = accept_prompt { click_link "Create or Update Invoice" }
distributor = order1.distributor
expect(message)
.to eq "#{distributor.name} must have a valid ABN before invoices can be used."
end
end
end
end
end
context "resumed" do
let!(:order2) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'resumed',
payment_state: 'balance_due')
}
before do
visit spree.edit_admin_order_path(order2)
end
it "displays the invoice tab" do
expect(page).to have_content "Resumed".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "canceled" do
let!(:order3) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'canceled',
payment_state: 'balance_due')
}
before do
visit spree.edit_admin_order_path(order3)
end
it "displays the invoice tab" do
expect(page).to have_content "Cancelled".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "cart" do
let!(:order_empty) {
create(:order_with_line_items, user:, distributor:, order_cycle:,
line_items_count: 0)
}
before do
visit spree.edit_admin_order_path(order_empty)
end
it "should not display the invoice tab" do
expect(page).to have_content "Cart".upcase
expect(page).not_to have_content "Invoices".upcase
end
end
context "payment" do
let!(:order4) do
create(:order_ready_for_payment, user:, distributor:,
order_cycle:,
payment_state: 'balance_due')
end
before do
visit spree.edit_admin_order_path(order4)
end
it "should not display the invoice tab" do
expect(page).to have_content "Payment".upcase
expect(page).not_to have_content "Invoices".upcase
end
end
end
end
end

View File

@@ -211,3 +211,178 @@ RSpec.describe '
end
end
end
RSpec.describe "Invoice order states", feature: :invoices do
let(:user) { create(:user) }
let(:product) { create(:simple_product) }
let(:distributor) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:order_cycle) do
create(:simple_order_cycle, name: 'One', distributors: [distributor],
variants: [product.variants.first])
end
let(:order) do
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'complete',
payment_state: 'balance_due')
end
let(:customer) { order.customer }
before do
order.finalize!
login_as user
end
context "complete" do
let!(:order1) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'complete',
payment_state: 'balance_due',
customer_id: customer.id)
}
context "editing the order" do
before do
visit spree.edit_admin_order_path(order1)
end
it "displays the invoice tab" do
expect(page).to have_content "Complete".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "visiting the invoices tab" do
let!(:table_header) {
[
"Date/Time",
"Invoice Number",
"Amount",
"Status",
"File",
].join(" ").upcase
}
let(:invoice_number){ "#{order.distributor_id}-1" }
let(:table_contents) {
[
Invoice.first.created_at.strftime('%B %d, %Y').to_s,
invoice_number,
"0.0",
"Active",
"Download"
].join(" ")
}
let(:download_href) {
"#{spree.print_admin_order_path(order1)}?invoice_id=#{Invoice.last.id}"
}
before do
Spree::Config[:enterprise_number_required_on_invoices?] = false
visit spree.admin_order_invoices_path(order1)
end
it "displays the invoices table" do
# with no invoices, only the table header is displayed
expect(page).to have_css "table.index"
expect(page).to have_content "#{customer.first_name} #{customer.last_name} -"
expect(page.find("table").text).to have_content(table_header)
# the New invoice button + the warning should be visible
expect(page).to have_link "Create or Update Invoice"
expect(page).to have_content "The order has changed since the last invoice update."
click_link "Create or Update Invoice"
# and disappear after clicking
expect(page).not_to have_link "Create or Update Invoice"
expect(page).not_to have_content "The order has changed since the last invoice update."
# creating an invoice, displays a second row
expect(page.find("table").text).to have_content(table_contents)
# with a valid invoice download link
expect(page).to have_link("Download",
href: download_href)
end
context "the Create or Update Invoice button" do
context "when an ABN number is mandatory for invoices but not present" do
before do
Spree::Config[:enterprise_number_required_on_invoices?] = true
end
it "displays a warning that an ABN is required when it's clicked" do
visit spree.admin_order_invoices_path(order1)
message = accept_prompt { click_link "Create or Update Invoice" }
distributor = order1.distributor
expect(message)
.to eq "#{distributor.name} must have a valid ABN before invoices can be used."
end
end
end
end
end
context "resumed" do
let!(:order2) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'resumed',
payment_state: 'balance_due')
}
before do
visit spree.edit_admin_order_path(order2)
end
it "displays the invoice tab" do
expect(page).to have_content "Resumed".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "canceled" do
let!(:order3) {
create(:order_with_totals_and_distribution, user:, distributor:,
order_cycle:, state: 'canceled',
payment_state: 'balance_due')
}
before do
visit spree.edit_admin_order_path(order3)
end
it "displays the invoice tab" do
expect(page).to have_content "Cancelled".upcase
expect(page).to have_content "Invoices".upcase
end
end
context "cart" do
let!(:order_empty) {
create(:order_with_line_items, user:, distributor:, order_cycle:,
line_items_count: 0)
}
before do
visit spree.edit_admin_order_path(order_empty)
end
it "should not display the invoice tab" do
expect(page).to have_content "Cart".upcase
expect(page).not_to have_content "Invoices".upcase
end
end
context "payment" do
let!(:order4) do
create(:order_ready_for_payment, user:, distributor:,
order_cycle:,
payment_state: 'balance_due')
end
before do
visit spree.edit_admin_order_path(order4)
end
it "should not display the invoice tab" do
expect(page).to have_content "Payment".upcase
expect(page).not_to have_content "Invoices".upcase
end
end
end