application_config_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2012-2022 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. before do
  17. gql.execute(query)
  18. end
  19. context 'with authenticated session', authenticated_as: :agent do
  20. it 'returns public data' do
  21. expect(gql.result.data).to include({ 'key' => 'product_name', 'value' => Setting.get('product_name') })
  22. end
  23. it 'returns internal data' do
  24. expect(gql.result.data).to include({ 'key' => 'system_id', 'value' => Setting.get('system_id') })
  25. end
  26. it 'returns data for Rails.application.config' do
  27. expect(gql.result.data).to include({
  28. 'key' => 'active_storage.web_image_content_types',
  29. 'value' => Rails.application.config.active_storage.web_image_content_types,
  30. })
  31. end
  32. it 'hides non-frontend data' do
  33. expect(gql.result.data.select { |s| s['key'].eql?('storage_provider') }).to be_empty
  34. end
  35. end
  36. context 'without authenticated session', authenticated_as: false do
  37. it 'returns public data' do
  38. expect(gql.result.data).to include({ 'key' => 'product_name', 'value' => Setting.get('product_name') })
  39. end
  40. it 'hides internal data' do
  41. expect(gql.result.data.select { |s| s['key'].eql?('system_id') }).to be_empty
  42. end
  43. # Not sure why, but that's how it is implemented...
  44. it 'hides all false values' do
  45. expect(gql.result.data.reject { |s| s['value'] }).to be_empty
  46. end
  47. it 'hides non-frontend data' do
  48. expect(gql.result.data.select { |s| s['key'].eql?('storage_provider') }).to be_empty
  49. end
  50. end
  51. end
  52. end