adds_metadata_general_spec.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Article::AddsMetadataGeneral do
  4. context 'when Agent creates Article' do
  5. shared_examples 'not including email in from' do |factory|
  6. subject(:article) { create(:ticket_article, factory, ticket: ticket, created_by_id: agent.id, updated_by_id: agent.id) }
  7. let(:ticket) { create(:ticket) }
  8. let!(:agent) { create(:agent, groups: [ticket.group]) }
  9. it "doesn't include email in from" do
  10. expect(article.from).not_to include agent.email
  11. end
  12. end
  13. it_behaves_like 'not including email in from', :outbound_phone
  14. it_behaves_like 'not including email in from', :outbound_web
  15. context 'when as Customer' do
  16. subject(:article) { create(:ticket_article, :inbound_phone, ticket: ticket) }
  17. let(:agent) { create(:agent) }
  18. let(:ticket) { create(:ticket, customer_id: agent.id) }
  19. it 'includes email in from' do
  20. expect(article.from).not_to include agent.email
  21. end
  22. end
  23. end
  24. context 'when Agent-Customer in shared organization creates Article' do
  25. let(:organization) { create(:organization, shared: true) }
  26. let(:agent_a) { create(:agent_and_customer, organization: organization) }
  27. let(:agent_b) { create(:agent_and_customer, organization: organization) }
  28. let(:group) { create(:group) }
  29. let(:ticket) { create(:ticket, group: group, owner: agent_a, customer: agent_b) }
  30. before do
  31. [agent_a, agent_b].each do |elem|
  32. elem.user_groups.create group: group, access: 'create'
  33. end
  34. end
  35. it '#origin_by is set correctly', current_user_id: -> { agent_a.id } do
  36. article = create(:ticket_article, :inbound_web, ticket: ticket)
  37. expect(article.origin_by).to be_nil
  38. end
  39. end
  40. context 'when Customer creates Article', current_user_id: -> { customer.id } do
  41. let(:ticket) { create(:ticket, customer:) }
  42. let(:article) { create(:ticket_article, :inbound_web, ticket:) }
  43. context 'when customer has email address' do
  44. let(:customer) { create(:customer) }
  45. it '#from is set correctly to customer full name and email' do
  46. # Names with Umlauts trigger quoting of the name, accept both variants.
  47. expect(article.from).to eq("#{customer.fullname} <#{customer.email}>").or(eq("\"#{customer.fullname}\" <#{customer.email}>"))
  48. end
  49. end
  50. context 'when customer has no email address' do
  51. let(:customer) { create(:customer, email: nil) }
  52. it '#from is set correctly to customer full name' do
  53. expect(article.from).to eq(customer.fullname)
  54. end
  55. end
  56. end
  57. end