|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +RSpec.describe 'application Query' do |
| 6 | + include GraphqlHelpers |
| 7 | + |
| 8 | + let(:query) do |
| 9 | + <<~QUERY |
| 10 | + query { |
| 11 | + application { |
| 12 | + settings { |
| 13 | + userRegistrationEnabled |
| 14 | + organizationCreationRestricted |
| 15 | + } |
| 16 | + metadata { |
| 17 | + version |
| 18 | + extensions |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | + QUERY |
| 23 | + end |
| 24 | + |
| 25 | + let(:current_user) { nil } |
| 26 | + |
| 27 | + before do |
| 28 | + post_graphql(query, current_user: current_user) |
| 29 | + end |
| 30 | + |
| 31 | + context 'when querying application settings' do |
| 32 | + let(:current_user) { create(:user, :admin) } |
| 33 | + |
| 34 | + it 'returns the application settings' do |
| 35 | + settings = graphql_data_at(:application, :settings) |
| 36 | + |
| 37 | + expect(settings['userRegistrationEnabled']) |
| 38 | + .to eq(ApplicationSetting.current['user_registration_enabled']) |
| 39 | + expect(settings['organizationCreationRestricted']) |
| 40 | + .to eq(ApplicationSetting.current['organization_creation_restricted']) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + it 'returns null application settings because of permissions' do |
| 45 | + settings = graphql_data_at(:application, :settings) |
| 46 | + expect(settings).to be_nil |
| 47 | + end |
| 48 | + |
| 49 | + it 'returns the application version' do |
| 50 | + expect(graphql_data_at(:application, :metadata, :version)).to eq(Sagittarius::Version) |
| 51 | + end |
| 52 | + |
| 53 | + it 'returns the list of active extensions' do |
| 54 | + expected_extensions = Sagittarius::Extensions.active.map(&:to_s) |
| 55 | + expect(graphql_data_at(:application, :metadata, :extensions)).to match_array(expected_extensions) |
| 56 | + end |
| 57 | + |
| 58 | + it 'does not require authentication' do |
| 59 | + expect(graphql_errors).to be_nil |
| 60 | + end |
| 61 | +end |
0 commit comments