adds_metadata_general_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Article::AddsMetadataGeneral do
  4. let(:agent) { create(:agent) }
  5. context 'when Agent creates Article' do
  6. shared_examples 'not including email in from' do |factory|
  7. subject(:article) { create(:ticket_article, factory, ticket: ticket, created_by_id: agent.id, updated_by_id: agent.id) }
  8. let(:ticket) { create(:ticket) }
  9. let!(:agent) { create(:agent, groups: [ticket.group]) }
  10. it "doesn't include email in from" do
  11. expect(article.from).not_to include agent.email
  12. end
  13. end
  14. it_behaves_like 'not including email in from', :outbound_phone
  15. it_behaves_like 'not including email in from', :outbound_web
  16. context 'when as Customer' do
  17. subject(:article) { create(:ticket_article, :inbound_phone, ticket: ticket) }
  18. let(:customer) { agent }
  19. let(:ticket) { create(:ticket, customer_id: customer.id) }
  20. it 'includes email in from' do
  21. expect(article.from).not_to include agent.email
  22. end
  23. end
  24. end
  25. context 'when Agent-Customer in shared organization creates Article' do
  26. let(:organization) { create(:organization, shared: true) }
  27. let(:agent_a) { create(:agent_and_customer, organization: organization) }
  28. let(:agent_b) { create(:agent_and_customer, organization: organization) }
  29. let(:group) { create(:group) }
  30. let(:ticket) { create(:ticket, group: group, owner: agent_a, customer: agent_b) }
  31. before do
  32. [agent_a, agent_b].each do |elem|
  33. elem.user_groups.create group: group, access: 'create'
  34. end
  35. end
  36. it '#origin_by is set correctly', current_user_id: -> { agent_a.id } do
  37. article = create(:ticket_article, :inbound_web, ticket: ticket)
  38. expect(article.origin_by).to be_nil
  39. end
  40. end
  41. end