Commit 87be392d authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'ensure-graphql-nil-checks-test-for-errors' into 'master'

Improve GraphQL tests that use nil checks

See merge request gitlab-org/gitlab!76328
parents 27228cba c2d28963
...@@ -36,8 +36,14 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do ...@@ -36,8 +36,14 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
end end
context 'when the user is not admin' do context 'when the user is not admin' do
it 'returns no data' do it 'returns an error' do
expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil expected_err = "The resource that you are attempting to access does not exist or you don't have permission to perform this action"
expect(subject["errors"].first["message"]).to eq(expected_err)
end
it 'does not return usageTrendsMeasurements data' do
expect(subject["data"]["usageTrendsMeasurements"]).to be_nil
end end
end end
...@@ -48,7 +54,7 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do ...@@ -48,7 +54,7 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
stub_application_setting(admin_mode: false) stub_application_setting(admin_mode: false)
end end
it 'returns data' do it 'returns usageTrendsMeasurements data' do
expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty
end end
end end
......
...@@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do ...@@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do
end end
describe 'query' do describe 'query' do
let_it_be(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) } let(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) }
let_it_be(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let(:query) do let(:query) do
...@@ -65,8 +65,12 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do ...@@ -65,8 +65,12 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do
project.ci_cd_settings.update!(job_token_scope_enabled: false) project.ci_cd_settings.update!(job_token_scope_enabled: false)
end end
it 'does not return an error' do
expect(subject['errors']).to be_nil
end
it 'returns nil' do it 'returns nil' do
expect(subject.dig('data', 'project', 'ciJobTokenScope')).to be_nil expect(subject['data']['project']['ciJobTokenScope']).to be_nil
end end
end end
end end
......
...@@ -66,10 +66,16 @@ RSpec.describe GitlabSchema.types['Issue'] do ...@@ -66,10 +66,16 @@ RSpec.describe GitlabSchema.types['Issue'] do
end end
context 'when user does not have the permission' do context 'when user does not have the permission' do
it 'returns no data' do before do
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(false) allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(false)
end
expect(subject.dig(:data, :project)).to eq(nil) it 'does not return an error' do
expect(subject['errors']).to be_nil
end
it 'returns no data' do
expect(subject['data']['project']).to be_nil
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment