diff --git a/spec/factories.rb b/spec/factories.rb index e10f351e9d..73a46e9109 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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) } diff --git a/spec/forms/enterprise_fees_bulk_update_spec.rb b/spec/forms/enterprise_fees_bulk_update_spec.rb index c569878200..f3d359f954 100644 --- a/spec/forms/enterprise_fees_bulk_update_spec.rb +++ b/spec/forms/enterprise_fees_bulk_update_spec.rb @@ -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 \ No newline at end of file +end end + end +end