application_config_spec.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::ApplicationConfig, type: :graphql do
  4. context 'when fetching the application config' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query applicationConfig {
  9. applicationConfig {
  10. key
  11. value
  12. }
  13. }
  14. QUERY
  15. end
  16. let(:setting) { nil }
  17. before do
  18. setting
  19. gql.execute(query)
  20. end
  21. context 'with authenticated session', authenticated_as: :agent do
  22. it 'returns public data' do
  23. expect(gql.result.data).to include({ 'key' => 'product_name', 'value' => Setting.get('product_name') })
  24. end
  25. it 'returns internal data' do
  26. expect(gql.result.data).to include({ 'key' => 'system_id', 'value' => Setting.get('system_id') })
  27. end
  28. it 'returns data for Rails.application.config' do
  29. expect(gql.result.data).to include({
  30. 'key' => 'active_storage.web_image_content_types',
  31. 'value' => Rails.application.config.active_storage.web_image_content_types,
  32. })
  33. end
  34. it 'hides non-frontend data' do
  35. expect(gql.result.data.select { |s| s['key'].eql?('storage_provider') }).to be_empty
  36. end
  37. it 'returns no display_name for auth_saml_credentials' do
  38. expect(gql.result.data).to include({
  39. 'key' => 'auth_saml_credentials.display_name',
  40. 'value' => nil,
  41. })
  42. end
  43. context 'when display_name for auth_saml_credentials is changed' do
  44. let(:setting) { Setting.set('auth_saml_credentials', Setting.get('auth_saml_credentials').merge(display_name: 'Zammad SAML')) }
  45. it 'returns changed display_name' do
  46. expect(gql.result.data).to include({
  47. 'key' => 'auth_saml_credentials.display_name',
  48. 'value' => 'Zammad SAML',
  49. })
  50. end
  51. end
  52. end
  53. context 'without authenticated session', authenticated_as: false do
  54. it 'returns public data' do
  55. expect(gql.result.data).to include({ 'key' => 'product_name', 'value' => Setting.get('product_name') })
  56. end
  57. it 'hides internal data' do
  58. expect(gql.result.data.select { |s| s['key'].eql?('system_id') }).to be_empty
  59. end
  60. # Not sure why, but that's how it is implemented...
  61. it 'hides all false values' do
  62. expect(gql.result.data.reject { |s| s['value'] }).to be_empty
  63. end
  64. it 'hides non-frontend data' do
  65. expect(gql.result.data.select { |s| s['key'].eql?('storage_provider') }).to be_empty
  66. end
  67. it 'returns no custom data if no changes are made' do
  68. expect(gql.result.data).not_to include({
  69. 'key' => 'auth_saml_credentials.display_name',
  70. 'value' => nil,
  71. })
  72. end
  73. context 'when display_name for auth_saml_credentials is changed' do
  74. let(:setting) { Setting.set('auth_saml_credentials', Setting.get('auth_saml_credentials').merge(display_name: 'Zammad SAML')) }
  75. it 'returns custom data if changes are made' do
  76. expect(gql.result.data).to include({
  77. 'key' => 'auth_saml_credentials.display_name',
  78. 'value' => 'Zammad SAML',
  79. })
  80. end
  81. end
  82. end
  83. end
  84. end