diff --git a/spec/services/order_data_masker_spec.rb b/spec/services/order_data_masker_spec.rb new file mode 100644 index 0000000000..70aeab7bd9 --- /dev/null +++ b/spec/services/order_data_masker_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe OrderDataMasker do + describe '#call' do + let(:distributor) { create(:enterprise) } + let(:order) { create(:order, distributor: distributor, ship_address: create(:address)) } + + context 'when displaying customer names is allowed' do + before { distributor.preferences[:show_customer_names_to_suppliers] = true } + + it 'masks personal addresses and email' do + described_class.new(order).call + + expect(order.bill_address.attributes).to include( + 'phone' => '', + 'address1' => '', + 'address2' => '', + 'city' => '', + 'zipcode' => '', + 'state_id' => nil + ) + + expect(order.ship_address.attributes).to include( + 'phone' => '', + 'address1' => '', + 'address2' => '', + 'city' => '', + 'zipcode' => '', + 'state_id' => nil + ) + + expect(order.email).to eq(I18n.t('admin.reports.hidden')) + end + + it 'does not mask the full name' do + described_class.new(order).call + + expect(order.bill_address.attributes).not_to include( + firstname: I18n.t('admin.reports.hidden'), + lastname: '' + ) + expect(order.ship_address.attributes).not_to include( + firstname: I18n.t('admin.reports.hidden'), + lastname: '' + ) + end + end + + context 'when displaying customer names is not allowed' do + before { distributor.preferences[:show_customer_names_to_suppliers] = false } + + it 'masks personal addresses and email' do + described_class.new(order).call + + expect(order.bill_address.attributes).to include( + 'phone' => '', + 'address1' => '', + 'address2' => '', + 'city' => '', + 'zipcode' => '', + 'state_id' => nil + ) + + expect(order.ship_address.attributes).to include( + 'phone' => '', + 'address1' => '', + 'address2' => '', + 'city' => '', + 'zipcode' => '', + 'state_id' => nil + ) + + expect(order.email).to eq(I18n.t('admin.reports.hidden')) + end + + it 'masks the full name' do + described_class.new(order).call + + expect(order.bill_address.attributes).to include( + 'firstname' => I18n.t('admin.reports.hidden'), + 'lastname' => '' + ) + expect(order.ship_address.attributes).to include( + 'firstname' => I18n.t('admin.reports.hidden'), + 'lastname' => '' + ) + end + end + end +end