Files
openfoodnetwork/spec/services/orders/mask_data_service_spec.rb
David Cook e02ef08b06 Consolidate translations for hidden field
The string '< Hidden >' was agreed on as a good default, so we will use the hidden_field key.
I also moved the definition in en.yml up to the more general area at the start of admin.reports section (before it was hidden between report-specific keys.
2025-03-31 16:24:07 +11:00

111 lines
3.2 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Orders::MaskDataService do
describe '#call' do
let(:distributor) { create(:enterprise) }
let(:order) { create(:order, distributor:, ship_address: create(:address)) }
shared_examples "mask customer name" do
it 'masks the full name' do
described_class.new(order).call
expect(order.bill_address.attributes).to include(
'firstname' => "< Hidden >",
'lastname' => ''
)
expect(order.ship_address.attributes).to include(
'firstname' => "< Hidden >",
'lastname' => ''
)
end
end
shared_examples "mask customer contact data" do
it 'masks personal phone and email' do
described_class.new(order).call
expect(order.bill_address.attributes).to include('phone' => '')
expect(order.ship_address.attributes).to include('phone' => '')
expect(order.email).to eq("< Hidden >")
end
end
shared_examples "mask customer address" do
it 'masks personal addresses' do
described_class.new(order).call
expect(order.bill_address.attributes).to include(
'address1' => '',
'address2' => '',
'city' => '',
'zipcode' => '',
'state_id' => nil
)
expect(order.ship_address.attributes).to include(
'address1' => '',
'address2' => '',
'city' => '',
'zipcode' => '',
'state_id' => nil
)
end
end
context 'when displaying customer names is allowed' do
before { distributor.show_customer_names_to_suppliers = true }
include_examples "mask customer contact data"
include_examples "mask customer address"
it 'does not mask the full name' do
described_class.new(order).call
expect(order.bill_address.attributes).not_to include(
firstname: "< Hidden >",
lastname: ''
)
expect(order.ship_address.attributes).not_to include(
firstname: "< Hidden >",
lastname: ''
)
end
end
context 'when displaying customer names is not allowed' do
before { distributor.show_customer_names_to_suppliers = false }
include_examples "mask customer name"
include_examples "mask customer contact data"
include_examples "mask customer address"
end
context 'when displaying customer contact data is allowed' do
before { distributor.show_customer_contacts_to_suppliers = true }
include_examples "mask customer name"
include_examples "mask customer address"
it 'does not mask the phone or email' do
described_class.new(order).call
expect(order.bill_address.attributes).not_to include('phone' => '')
expect(order.ship_address.attributes).not_to include('phone' => '')
expect(order.email).not_to eq("< Hidden >")
end
end
context 'when displaying customer contact data is not allowed' do
before { distributor.show_customer_contacts_to_suppliers = false }
include_examples "mask customer name"
include_examples "mask customer contact data"
include_examples "mask customer address"
end
end
end