generic_object_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Kayako::GenericObject, db_strategy: :reset, sequencer: :sequence do
  4. context 'when importing group list with generic object' do
  5. let(:resources_payloud) do
  6. {
  7. 'data' => [
  8. {
  9. 'id' => 80_000_374_715,
  10. 'legacy_id' => nil,
  11. 'title' => 'Support',
  12. 'businesshour' => {
  13. 'id' => 1,
  14. 'resource_type' => 'business_hour'
  15. },
  16. 'member_count' => 0,
  17. 'created_at' => '2021-08-16T13:42:26+00:00',
  18. 'updated_at' => '2021-08-16T13:42:26+00:00',
  19. 'resource_type' => 'team',
  20. },
  21. {
  22. 'id' => 80_000_374_716,
  23. 'legacy_id' => nil,
  24. 'title' => 'Sales',
  25. 'businesshour' => {
  26. 'id' => 1,
  27. 'resource_type' => 'business_hour'
  28. },
  29. 'member_count' => 0,
  30. 'created_at' => '2021-08-16T13:42:26+00:00',
  31. 'updated_at' => '2021-08-16T13:42:26+00:00',
  32. 'resource_type' => 'team',
  33. }
  34. ]
  35. }
  36. end
  37. let(:process_payload) do
  38. {
  39. import_job: build_stubbed(:import_job, name: 'Import::Kayako', payload: {}),
  40. dry_run: false,
  41. object: 'Team',
  42. request_params: {},
  43. field_map: {},
  44. id_map: {},
  45. default_language: 'en-us'
  46. }
  47. end
  48. before do
  49. # Mock the groups get request
  50. stub_request(:get, 'https://yours.kayako.com/api/v1/teams?limit=100').to_return(status: 200, body: JSON.generate(resources_payloud), headers: {})
  51. end
  52. it 'add groups' do
  53. expect { process(process_payload) }.to change(Group, :count).by(2)
  54. end
  55. context 'when list request fails' do
  56. before do
  57. allow(Sequencer::Unit::Import::Kayako::Request).to receive(:handle_error).with(any_args).and_return(true)
  58. stub_request(:get, 'https://yours.kayako.com/api/v1/teams?limit=100').to_return(status: 400, headers: {})
  59. end
  60. it 'check that a failing response do not raise a hard error' do
  61. expect { process(process_payload) }.not_to change(Group, :count)
  62. end
  63. end
  64. end
  65. end