mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add tests for Enterprise Fees Bulk Update
This commit is contained in:
@@ -99,24 +99,6 @@ FactoryBot.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :enterprise_fee_bulk_update, class: Forms::EnterpriseFeesBulkUpdate do
|
||||
transient { enterprise_fee { build(:enterprise_fee)}}
|
||||
|
||||
collection_attributes do
|
||||
{
|
||||
[
|
||||
id: enterprise_fee.id,
|
||||
enterprise_id: enterprise_fee.enterprise_id,
|
||||
fee_type: enterprise_fee.fee_type,
|
||||
name: enterprise_fee.name,
|
||||
tax_category_id: enterprise_fee.tax_category_id,
|
||||
inherits_tax_category: enterprise_fee.inherits_tax_category,
|
||||
calculator_type: enterprise_fee.calculator_type,
|
||||
{ calculator_attributes: enterprise_fee.calculator.attributes }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
factory :adjustment_metadata, class: AdjustmentMetadata do
|
||||
adjustment { FactoryBot.create(:adjustment) }
|
||||
enterprise { FactoryBot.create(:distributor_enterprise) }
|
||||
|
||||
@@ -2,16 +2,50 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Forms::EnterpriseFeesBulkUpdate do
|
||||
describe "error reporting" do
|
||||
it "adds errors from set creation" do
|
||||
subject = build(:enterprise_fee_bulk_update)
|
||||
describe EnterpriseFeesBulkUpdate do
|
||||
describe "error reporting" do
|
||||
let(:enterprise_fee) { build_stubbed(:enterprise_fee) }
|
||||
let(:base_attributes) do
|
||||
attributes = enterprise_fee.attributes.symbolize_keys
|
||||
attributes[:calculator_type] = enterprise_fee.calculator_type
|
||||
attributes[:calculator_attributes] = enterprise_fee.calculator.attributes
|
||||
attributes
|
||||
end
|
||||
let(:valid_attributes) do
|
||||
set_attributes = {
|
||||
sets_enterprise_fee_set: {
|
||||
collection_attributes: {
|
||||
"0" => base_attributes
|
||||
}
|
||||
}
|
||||
}
|
||||
ActionController::Parameters.new(set_attributes)
|
||||
end
|
||||
let(:invalid_attributes) do
|
||||
base_attributes[:inherits_tax_category] = "true"
|
||||
base_attributes[:calculator_type] = EnterpriseFee::PER_ORDER_CALCULATORS.first
|
||||
base_attributes[:calculator_attributes].merge!(preferred_amount: "%12")
|
||||
set_attributes = {
|
||||
sets_enterprise_fee_set: {
|
||||
collection_attributes: {
|
||||
"0" => base_attributes
|
||||
}
|
||||
}
|
||||
}
|
||||
ActionController::Parameters.new(set_attributes)
|
||||
end
|
||||
|
||||
end
|
||||
it "creates a valid form with valid parameters" do
|
||||
subject = EnterpriseFeesBulkUpdate.new(valid_attributes)
|
||||
subject.save
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user