base_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sessions::Backend::Base do
  4. subject(:backend) { described_class.new(agent, {}, false, client_id, ttl) }
  5. let(:agent) { create(:agent) }
  6. let(:client_id) { '123-1' }
  7. let(:ttl) { 3 } # seconds
  8. let!(:ticket) { Ticket.first || create(:ticket) }
  9. describe '#asset_needed?' do
  10. context 'before #asset_push has ever been called for the given record' do
  11. it 'returns true' do
  12. expect(backend.asset_needed?(ticket)).to be(true)
  13. end
  14. end
  15. context 'when #asset_push was previously called for the given record' do
  16. before { backend.asset_push(ticket, {}) }
  17. it 'returns false' do
  18. expect(backend.asset_needed?(ticket)).to be(false)
  19. end
  20. context 'within two hours of the backend’s #time_now value' do
  21. before { backend.time_now = (2.hours - 1.second).from_now.to_i }
  22. it 'returns false' do
  23. expect(backend.asset_needed?(ticket)).to be(false)
  24. end
  25. end
  26. context 'over two hours before the backend’s #time_now value' do
  27. before { backend.time_now = (2.hours + 1.second).from_now.to_i }
  28. it 'returns true' do
  29. expect(backend.asset_needed?(ticket)).to be(true)
  30. end
  31. end
  32. context 'prior to the record’s last update' do
  33. before { ticket.touch }
  34. it 'returns true' do
  35. expect(backend.asset_needed?(ticket)).to be(true)
  36. end
  37. end
  38. end
  39. end
  40. describe '#asset_needed_by_updated_at?' do
  41. let(:method_args) { [ticket.class.name, ticket.id, ticket.updated_at] }
  42. context 'before #asset_push has ever been called for the given record' do
  43. it 'returns true' do
  44. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  45. end
  46. end
  47. context 'when #asset_push was previously called for the given record' do
  48. before { backend.asset_push(ticket, {}) }
  49. it 'returns false' do
  50. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(false)
  51. end
  52. context 'within two hours of the backend’s #time_now value' do
  53. before { backend.time_now = (2.hours - 1.second).from_now.to_i }
  54. it 'returns false' do
  55. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(false)
  56. end
  57. end
  58. context 'over two hours before the backend’s #time_now value' do
  59. before { backend.time_now = (2.hours + 1.second).from_now.to_i }
  60. it 'returns true' do
  61. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  62. end
  63. end
  64. context 'prior to the record’s last update' do
  65. before { ticket.touch }
  66. it 'returns true' do
  67. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  68. end
  69. end
  70. end
  71. end
  72. describe '#asset_push' do
  73. it 'returns the assets for the given record' do
  74. expect(backend.asset_push(ticket, {})).to eq(ticket.assets({}))
  75. end
  76. end
  77. end