adds_metadata_whatsapp_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Article::AddsMetadataWhatsapp do
  4. let(:agent) { create(:agent) }
  5. let(:ticket) do
  6. article = create(:whatsapp_article, :inbound)
  7. article.ticket
  8. end
  9. let(:channel) { Channel.lookup(id: ticket.preferences['channel_id']) }
  10. let(:ticket_whatsapp_from) { ticket.preferences.dig('whatsapp', 'from') }
  11. context 'when agent creates whatsapp reply article' do
  12. subject(:article) { create(:ticket_article, sender_name: 'Agent', type_name: 'whatsapp message', ticket: ticket, created_by_id: agent.id, updated_by_id: agent.id) }
  13. it 'adds agent name and channel name in from' do
  14. expect(article.from).to eq("#{agent.firstname} #{agent.lastname} via #{channel.options[:name]} (#{channel.options[:phone_number]})")
  15. end
  16. it 'adds correct to value' do
  17. expect(article.to).to eq("#{ticket_whatsapp_from[:display_name]} (+#{ticket_whatsapp_from[:phone_number]})")
  18. end
  19. context 'when agent is system user' do
  20. let(:agent) { User.lookup(id: 1) }
  21. it 'adds agent name and channel name in from' do
  22. expect(article.from).to eq("#{channel.options[:name]} (#{channel.options[:phone_number]})")
  23. end
  24. end
  25. end
  26. end