agent_reemit_job_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'rails_helper'
  2. describe AgentReemitJob do
  3. subject { described_class.new }
  4. let(:agent) { agents(:bob_website_agent) }
  5. let(:agent_event) { events(:bob_website_agent_event) }
  6. it "re-emits all events created by the given Agent" do
  7. 2.times { agent_event.dup.save! }
  8. expect {
  9. subject.perform(agent, agent.most_recent_event.id)
  10. }.to change(Event, :count).by(3)
  11. last_event = Event.last
  12. expect(last_event.user).to eq(agent_event.user)
  13. expect(last_event.agent).to eq(agent_event.agent)
  14. expect(last_event.payload).to eq(agent_event.payload)
  15. end
  16. it "doesn't re-emit events created after the the most_recent_event_id" do
  17. 2.times { agent_event.dup.save! }
  18. # create one more
  19. most_recent_event = agent.most_recent_event.id
  20. agent_event.dup.save!
  21. expect {
  22. subject.perform(agent, most_recent_event, false)
  23. }.to change(Event, :count).by(3)
  24. last_event = Event.last
  25. expect(last_event.user).to eq(agent_event.user)
  26. expect(last_event.agent).to eq(agent_event.agent)
  27. expect(last_event.payload).to eq(agent_event.payload)
  28. end
  29. context "when delete_old_events set to true" do
  30. it "re-emits all events created by the given Agent and destroys originals" do
  31. original_events = [agent_event]
  32. 2.times do
  33. original_events << agent_event.dup.tap{ |e| e.save! }
  34. end
  35. expect {
  36. subject.perform(agent, agent.most_recent_event.id, true)
  37. }.to change(Event, :count).by(0)
  38. original_events.each { |e| expect(e.destroyed?) }
  39. last_event = Event.last
  40. expect(last_event.user).to eq(agent_event.user)
  41. expect(last_event.agent).to eq(agent_event.agent)
  42. expect(last_event.payload).to eq(agent_event.payload)
  43. end
  44. end
  45. end