preload_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Channel::Whatsapp::Preload do
  4. subject(:service) { described_class.new(**params) }
  5. describe '#execute' do
  6. context 'with all params' do
  7. let(:params) do
  8. {
  9. business_id: Faker::Number.unique.number(digits: 15),
  10. access_token: Faker::Omniauth.unique.facebook[:credentials][:token],
  11. }
  12. end
  13. let(:internal_response) do
  14. {
  15. Faker::Number.unique.number(digits: 15) => format('%{name} (%{number})', name: Faker::Name.unique.name, number: Faker::PhoneNumber.unique.cell_phone_with_country_code),
  16. Faker::Number.unique.number(digits: 15) => format('%{name} (%{number})', name: Faker::Name.unique.name, number: Faker::PhoneNumber.unique.cell_phone_with_country_code),
  17. Faker::Number.unique.number(digits: 15) => format('%{name} (%{number})', name: Faker::Name.unique.name, number: Faker::PhoneNumber.unique.cell_phone_with_country_code),
  18. }
  19. end
  20. before do
  21. allow_any_instance_of(Whatsapp::Account::PhoneNumbers).to receive(:all).and_return(internal_response)
  22. end
  23. it 'returns phone number options' do
  24. expect(service.execute).to eq(phone_numbers: internal_response.map { |value, label| { value:, label: } })
  25. end
  26. end
  27. end
  28. end