whatsapp_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Channel::Area::Whatsapp, type: :model do
  4. describe 'validations' do
  5. let(:another_channel) { create(:whatsapp_channel, phone_number_id:) }
  6. let(:phone_number_id) { 123_456_780 }
  7. before { another_channel }
  8. it 'allows to create another channel with a different phone number' do
  9. channel = create(:whatsapp_channel)
  10. expect(channel).to be_persisted
  11. end
  12. it 'does not allow to create another channel with the same phone number' do
  13. channel = build(:whatsapp_channel, phone_number_id:).tap(&:save)
  14. expect(channel.errors.full_messages).to include(%r{Phone number is already in use})
  15. end
  16. it 'allows to edit an existing channel' do
  17. channel = create(:whatsapp_channel)
  18. channel.options[:test] = true
  19. expect { channel.save! }.not_to raise_error
  20. end
  21. it 'not applicable to other areas' do
  22. expect_any_instance_of(Channel).not_to receive(:validate_whatsapp_phone_number)
  23. create(:google_channel)
  24. end
  25. end
  26. end