Files
openfoodnetwork/spec/services/order_data_masker_spec.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

93 lines
2.5 KiB
Ruby

# frozen_string_literal: true
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