time_entry_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::TimeEntry, sequencer: :sequence do
  4. context 'when importing time_entry from Freshdesk' do
  5. let(:resource) do
  6. {
  7. 'id' => 80_027_218_656,
  8. 'billable' => true,
  9. 'note' => 'Example Preparation',
  10. 'timer_running' => false,
  11. 'agent_id' => 80_014_400_475,
  12. 'ticket_id' => 1001,
  13. 'time_spent' => '01:20',
  14. 'created_at' => '2021-05-14T12:29:27Z',
  15. 'updated_at' => '2021-05-14T12:29:27Z',
  16. 'start_time' => '2021-05-14T12:29:27Z',
  17. 'executed_at' => '2021-05-14T12:29:27Z'
  18. }
  19. end
  20. let(:ticket) { create(:ticket) }
  21. let(:id_map) do
  22. {
  23. 'Ticket' => {
  24. 1001 => ticket.id,
  25. },
  26. 'User' => {
  27. 80_014_400_475 => 1,
  28. }
  29. }
  30. end
  31. let(:process_payload) do
  32. {
  33. import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
  34. dry_run: false,
  35. resource: resource,
  36. field_map: {},
  37. id_map: id_map,
  38. skip_initial_contacts: false,
  39. }
  40. end
  41. let(:imported_time_entry) do
  42. {
  43. ticket_id: ticket.id,
  44. created_by_id: 1,
  45. time_unit: 80,
  46. }
  47. end
  48. it 'adds time entry' do
  49. expect { process(process_payload) }.to change(Ticket::TimeAccounting, :count).by(1)
  50. end
  51. it 'correct attributes for added time entry' do
  52. process(process_payload)
  53. Rails.logger.debug Ticket::TimeAccounting.last
  54. expect(Ticket::TimeAccounting.last).to have_attributes(imported_time_entry)
  55. end
  56. it 'updates already existing article' do
  57. expect do
  58. process(process_payload)
  59. process(process_payload)
  60. end.to change(Ticket::TimeAccounting, :count).by(1)
  61. end
  62. end
  63. end