generic_object_spec.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::GenericObject, db_strategy: 'reset', sequencer: :sequence do
  4. context 'when importing group list with generic object' do
  5. let(:resources_payloud) do
  6. [
  7. {
  8. 'id' => 80_000_374_715,
  9. 'name' => 'QA',
  10. 'description' => 'Members of the QA team belong to this group',
  11. 'escalate_to' => nil,
  12. 'unassigned_for' => nil,
  13. 'business_hour_id' => nil,
  14. 'group_type' => 'support_agent_group',
  15. 'created_at' => '2021-04-09T13:23:59Z',
  16. 'updated_at' => '2021-04-09T13:23:59Z'
  17. },
  18. {
  19. 'id' => 80_000_374_716,
  20. 'name' => 'Testing',
  21. 'description' => 'Members of the Testing team belong to this group',
  22. 'escalate_to' => nil,
  23. 'unassigned_for' => nil,
  24. 'business_hour_id' => nil,
  25. 'group_type' => 'support_agent_group',
  26. 'created_at' => '2021-04-09T13:23:59Z',
  27. 'updated_at' => '2021-04-09T13:23:59Z'
  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. object: 'Group',
  36. request_params: {},
  37. field_map: {},
  38. id_map: {},
  39. skipped_resource_id: nil,
  40. time_entry_available: true,
  41. skip_initial_contacts: false,
  42. }
  43. end
  44. before do
  45. # Mock the groups get request
  46. stub_request(:get, 'https://yours.freshdesk.com/api/v2/groups?per_page=100').to_return(status: 200, body: JSON.generate(resources_payloud), headers: {})
  47. end
  48. it 'add groups' do
  49. expect { process(process_payload) }.to change(Group, :count).by(2)
  50. end
  51. context 'when list request fails' do
  52. before do
  53. allow(Sequencer::Unit::Import::Freshdesk::Request).to receive(:handle_error).with(any_args).and_return(true)
  54. stub_request(:get, 'https://yours.freshdesk.com/api/v2/groups?per_page=100').to_return(status: 400, headers: {})
  55. end
  56. it 'check that a failing response do not raise a hard error' do
  57. expect { process(process_payload) }.not_to change(Group, :count)
  58. end
  59. end
  60. end
  61. end