adds_metadata_general_spec.rb 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2012-2025 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:, body: 'Entdecken Sie jetzt das Zammad Ticketsystem!') }
  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. context 'when it contains a detectable languages inside the body' do
  57. let(:customer) { create(:customer) }
  58. context 'when language detection for article is turned on' do
  59. before { Setting.set('language_detection_article', true) }
  60. it 'does detect the german locale' do
  61. expect(article.detected_language).to eq('de')
  62. end
  63. end
  64. context 'when language detection for article is turned off' do
  65. before { Setting.set('language_detection_article', false) }
  66. it 'does not detect the german locale' do
  67. expect(article.detected_language).to be_blank
  68. end
  69. end
  70. end
  71. end
  72. end