add tests (integration + model)
This commit is contained in:
parent
eadfbd5969
commit
298a476061
3 changed files with 129 additions and 0 deletions
7
spec/factories/group_order_invoice.rb
Normal file
7
spec/factories/group_order_invoice.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'factory_bot'
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :group_order_invoice do
|
||||||
|
group_order{ create :group_order}
|
||||||
|
end
|
||||||
|
end
|
61
spec/integration/group_order_invoices_spec.rb
Normal file
61
spec/integration/group_order_invoices_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
|
feature GroupOrderInvoice, js: true do
|
||||||
|
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
||||||
|
let(:article) { create :article, unit_quantity: 1 }
|
||||||
|
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id], ends: Time.now } # need to ref article
|
||||||
|
let(:go) { create :group_order, order: order }
|
||||||
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||||
|
let(:ftt) { create :financial_transaction_type }
|
||||||
|
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe 'trigger process' do
|
||||||
|
|
||||||
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
|
before { login admin }
|
||||||
|
after { clear_enqueued_jobs }
|
||||||
|
|
||||||
|
it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do
|
||||||
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
visit confirm_finance_order_path(id: order.id)
|
||||||
|
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||||
|
expect(NotifyGroupOrderInvoiceJob).not_to have_been_enqueued
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'enqueues MailerJob when order is settled if tax_number or options are set' do
|
||||||
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
order.reload
|
||||||
|
FoodsoftConfig[:group_order_invoices] = { use: true }
|
||||||
|
FoodsoftConfig[:contact][:tax_number] = 12345678
|
||||||
|
visit confirm_finance_order_path(id: order.id, type: ftt)
|
||||||
|
expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear'))
|
||||||
|
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||||
|
expect(NotifyGroupOrderInvoiceJob).to have_been_enqueued
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not generate Group Order Invoice when order is closed if tax_number not set' do
|
||||||
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
order.update!(state: 'closed')
|
||||||
|
order.reload
|
||||||
|
visit finance_order_index_path
|
||||||
|
expect(page).to have_content(I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'generates Group Order Invoice when order is closed if tax_number is set' do
|
||||||
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
FoodsoftConfig[:contact][:tax_number] = 12345678
|
||||||
|
order.update!(state: 'closed')
|
||||||
|
order.reload
|
||||||
|
visit finance_order_index_path
|
||||||
|
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate')
|
||||||
|
expect(GroupOrderInvoice.all.count).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
61
spec/models/group_order_invoice_spec.rb
Normal file
61
spec/models/group_order_invoice_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
|
describe GroupOrderInvoice do
|
||||||
|
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||||
|
let(:supplier) { create :supplier }
|
||||||
|
let(:article) { create :article, supplier: supplier }
|
||||||
|
let(:order){ create :order }
|
||||||
|
let(:group_order) {create :group_order, order: order, ordergroup: user.ordergroup }
|
||||||
|
|
||||||
|
describe 'erroneous group order invoice' do
|
||||||
|
let(:goi) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
|
|
||||||
|
it 'does not create group order invoice if tax_number not set' do
|
||||||
|
expect{goi}.to raise_error(ActiveRecord::RecordInvalid)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'valid group order invoice' do
|
||||||
|
before do
|
||||||
|
FoodsoftConfig[:contact][:tax_number] = 12345678
|
||||||
|
end
|
||||||
|
|
||||||
|
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
|
||||||
|
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
|
||||||
|
|
||||||
|
let(:user_2) { create :user, groups: [create(:ordergroup)] }
|
||||||
|
|
||||||
|
let(:goi_1) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
|
let(:goi_2) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
|
|
||||||
|
let(:group_order_2) {create :group_order, order: order, ordergroup: user_2.ordergroup }
|
||||||
|
|
||||||
|
let(:goi_3) { create :group_order_invoice, group_order_id: group_order_2.id }
|
||||||
|
let(:goi_4) { create :group_order_invoice, group_order_id: group_order_2.id, invoice_number: invoice_number1 }
|
||||||
|
|
||||||
|
it 'creates group order invoice if tax_number is set' do
|
||||||
|
expect(goi_1).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sets invoice_number according to date' do
|
||||||
|
number = Time.now.strftime("%Y%m%d") + '0001'
|
||||||
|
expect(goi_1.invoice_number).to eq(number.to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fails to create if group_order_id is used multiple times for creation' do
|
||||||
|
expect(goi_1.group_order.id).to eq(group_order.id)
|
||||||
|
expect{goi_2}.to raise_error(ActiveRecord::RecordNotUnique)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates two different group order invoice with different invoice_numbers' do
|
||||||
|
expect(goi_1.invoice_number).to eq(invoice_number1.to_i)
|
||||||
|
expect(goi_3.invoice_number).to eq(invoice_number2.to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fails to create two different group order invoice with same invoice_numbers' do
|
||||||
|
goi_1
|
||||||
|
expect{goi_4}.to raise_error(ActiveRecord::RecordInvalid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue