adds_metadata_general_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. expect(article.from).to eq("#{customer.fullname} <#{customer.email}>")
  47. end
  48. end
  49. context 'when customer has no email address' do
  50. let(:customer) { create(:customer, email: nil) }
  51. it '#from is set correctly to customer full name' do
  52. expect(article.from).to eq(customer.fullname)
  53. end
  54. end
  55. end
  56. end