state_spec.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::System::Import::State, type: :graphql do
  4. context 'when checking system import state' do
  5. let(:query) do
  6. <<~QUERY
  7. query systemImportState {
  8. systemImportState {
  9. name
  10. result
  11. startedAt
  12. finishedAt
  13. }
  14. }
  15. QUERY
  16. end
  17. context 'with a running import job' do
  18. before do
  19. Setting.set('import_backend', 'freshdesk')
  20. Setting.set('import_mode', true)
  21. ImportJob.create!(name: 'Import::Freshdesk')
  22. end
  23. it 'returns the state' do
  24. gql.execute(query)
  25. expect(gql.result.data).to be_present.and(include('name' => 'Import::Freshdesk'))
  26. end
  27. context 'when the import source is OTRS' do
  28. let(:status) do
  29. {
  30. data: {
  31. Base: {
  32. done: 1,
  33. total: 100
  34. },
  35. User: {
  36. done: 10,
  37. total: 10
  38. },
  39. Ticket: {
  40. done: 334,
  41. total: 11_472
  42. }
  43. },
  44. result: 'in_progress'
  45. }
  46. end
  47. before do
  48. Setting.set('import_backend', 'otrs')
  49. Setting.set('import_mode', true)
  50. allow_any_instance_of(Service::System::Import::CheckStatus).to receive(:execute).and_return(status)
  51. end
  52. context 'when the import is in progress' do
  53. it 'returns the state' do
  54. gql.execute(query)
  55. expect(gql.result.data).to be_present.and(include('name' => 'Import::Otrs'))
  56. end
  57. end
  58. context 'when error occurs during the import' do
  59. let(:status) do
  60. {
  61. message: 'Some error occurs during customer user creation.',
  62. result: 'error'
  63. }
  64. end
  65. it 'returns the error state' do
  66. gql.execute(query)
  67. expect(gql.result.data).to be_present.and(include('name' => 'Import::Otrs', 'result' => { error: 'Some error occurs during customer user creation.' }))
  68. end
  69. end
  70. end
  71. end
  72. context 'with finished import job' do
  73. before do
  74. Setting.set('import_backend', 'freshdesk')
  75. Setting.set('system_init_done', true)
  76. create(:admin)
  77. ImportJob.create!(name: 'Import::Freshdesk')
  78. end
  79. it 'returns the state' do
  80. gql.execute(query)
  81. expect(gql.result.data).to be_present.and(include('name' => 'Import::Freshdesk'))
  82. end
  83. end
  84. context 'with no running import job' do
  85. before do
  86. Setting.set('import_backend', 'freshdesk')
  87. end
  88. it 'returns the state' do
  89. gql.execute(query)
  90. expect(gql.result.data).to include({ 'result' => { error: 'No import in progress.' } })
  91. end
  92. end
  93. end
  94. end