run_auto_wizard_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::System::Setup::RunAutoWizard, :aggregate_failures, set_up: false, type: :request do
  4. context 'when running the auto wizard' do
  5. let(:query) do
  6. <<~QUERY
  7. mutation systemSetupRunAutoWizard($token: String) {
  8. systemSetupRunAutoWizard(token: $token) {
  9. session {
  10. id
  11. afterAuth {
  12. type
  13. data
  14. }
  15. }
  16. errors {
  17. message
  18. field
  19. }
  20. }
  21. }
  22. QUERY
  23. end
  24. let(:variables) { { token: } }
  25. let(:token) { nil }
  26. let(:headers) { { 'X-Browser-Fingerprint' => 'some-fingerprint' } }
  27. let(:graphql_response) do
  28. post '/graphql', params: { query: query, variables: variables }, headers: headers, as: :json
  29. json_response
  30. end
  31. context 'with auto wizard not enabled' do
  32. it 'fails with an error' do
  33. expect(graphql_response['data']['systemSetupRunAutoWizard']['errors'].first['message']).to eq('An unexpected error occurred during system setup.')
  34. end
  35. end
  36. context 'with auto wizard enabled' do
  37. before do
  38. FileUtils.cp(Rails.root.join('contrib/auto_wizard_example.json'), Rails.root.join('auto_wizard.json'))
  39. end
  40. after do
  41. FileUtils.rm(Rails.root.join('auto_wizard.json'), force: true)
  42. end
  43. context 'without the right token' do
  44. it 'fails with an error' do
  45. expect(graphql_response['data']['systemSetupRunAutoWizard']['errors'].first['message']).to eq('An unexpected error occurred during system setup.')
  46. end
  47. end
  48. context 'with the right token' do
  49. let(:token) { 'secret_token' }
  50. it 'runs the auto wizard' do
  51. expect(graphql_response['data']['systemSetupRunAutoWizard']).to include({ 'session' => include({ 'id' => a_kind_of(String) }), 'errors' => nil })
  52. expect(User.find_by(email: 'hans.atila@zammad.org')).to be_present
  53. expect(Setting.get('system_init_done')).to be true
  54. end
  55. end
  56. end
  57. end
  58. end