Commit c2d28963 authored by Adam Cohen's avatar Adam Cohen Committed by Mikołaj Wawrzyniak

Improve GraphQL tests that use nil checks

parent b8597825
......@@ -36,8 +36,14 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
end
context 'when the user is not admin' do
it 'returns no data' do
expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil
it 'returns an error' do
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
......@@ -48,7 +54,7 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
stub_application_setting(admin_mode: false)
end
it 'returns data' do
it 'returns usageTrendsMeasurements data' do
expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty
end
end
......
......@@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do
end
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(:query) do
......@@ -65,8 +65,12 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do
project.ci_cd_settings.update!(job_token_scope_enabled: false)
end
it 'does not return an error' do
expect(subject['errors']).to be_nil
end
it 'returns nil' do
expect(subject.dig('data', 'project', 'ciJobTokenScope')).to be_nil
expect(subject['data']['project']['ciJobTokenScope']).to be_nil
end
end
end
......
......@@ -66,10 +66,16 @@ RSpec.describe GitlabSchema.types['Issue'] do
end
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)
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
......
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