time_entry_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Kayako::TimeEntry, sequencer: :sequence do
  4. context 'when importing time_entry from Kayako' do
  5. let(:resource) do
  6. {
  7. 'id' => 51,
  8. 'time_tracking_log_id' => 51,
  9. 'case' => {
  10. 'id' => 1001,
  11. 'resource_type' => 'case'
  12. },
  13. 'agent' => {
  14. 'id' => 80_014_400_475,
  15. 'resource_type' => 'user'
  16. },
  17. 'log_type' => 'WORKED',
  18. 'time_spent' => 3600,
  19. 'creator' => {
  20. 'id' => 80_014_400_475,
  21. 'resource_type' => 'user'
  22. },
  23. 'created_at' => '2021-08-27T20:38:30+00:00',
  24. 'updated_at' => '2021-08-27T20:38:30+00:00',
  25. 'resource_type' => 'timetracking_log',
  26. }
  27. end
  28. let(:ticket) { create(:ticket) }
  29. let(:id_map) do
  30. {
  31. 'Ticket' => {
  32. 1001 => ticket.id,
  33. },
  34. 'User' => {
  35. 80_014_400_475 => 1,
  36. }
  37. }
  38. end
  39. let(:process_payload) do
  40. {
  41. import_job: build_stubbed(:import_job, name: 'Import::Kayako', payload: {}),
  42. dry_run: false,
  43. resource: resource,
  44. field_map: {},
  45. id_map: id_map,
  46. default_language: 'en-us'
  47. }
  48. end
  49. let(:imported_time_entry) do
  50. {
  51. ticket_id: ticket.id,
  52. created_by_id: 1,
  53. time_unit: 60,
  54. }
  55. end
  56. it 'adds time entry' do
  57. expect { process(process_payload) }.to change(Ticket::TimeAccounting, :count).by(1)
  58. end
  59. it 'correct attributes for added time entry' do
  60. process(process_payload)
  61. expect(Ticket::TimeAccounting.last).to have_attributes(imported_time_entry)
  62. end
  63. context 'when time entry should be skipped' do
  64. let(:resource) do
  65. super().merge(
  66. 'log_type' => 'VIEWED'
  67. )
  68. end
  69. it 'skip time entry' do
  70. expect { process(process_payload) }.not_to change(Ticket::TimeAccounting, :count)
  71. end
  72. end
  73. end
  74. end