Skip to content
Snippets Groups Projects
Commit 972d93ba authored by Brett Walker's avatar Brett Walker
Browse files

Fix specs checking for an error to be raised

now those exceptions are being returned in GraphQL,
not raised
parent 3d873e41
No related branches found
No related tags found
No related merge requests found
Pipeline #337884052 failed
Pipeline: GitLab

#337884167

    Showing
    with 48 additions and 61 deletions
    ...@@ -11,8 +11,8 @@ class GitlabSchema < GraphQL::Schema ...@@ -11,8 +11,8 @@ class GitlabSchema < GraphQL::Schema
    AUTHENTICATED_MAX_DEPTH = 20 AUTHENTICATED_MAX_DEPTH = 20
    # use new GraphQL interpreter # use new GraphQL interpreter
    # use GraphQL::Execution::Interpreter use GraphQL::Execution::Interpreter
    # use GraphQL::Analysis::AST use GraphQL::Analysis::AST
    use GraphQL::Subscriptions::ActionCableSubscriptions use GraphQL::Subscriptions::ActionCableSubscriptions
    use GraphQL::Pagination::Connections use GraphQL::Pagination::Connections
    ...@@ -21,10 +21,10 @@ class GitlabSchema < GraphQL::Schema ...@@ -21,10 +21,10 @@ class GitlabSchema < GraphQL::Schema
    use Gitlab::Graphql::GenericTracing use Gitlab::Graphql::GenericTracing
    use Gitlab::Graphql::Timeout, max_seconds: Gitlab.config.gitlab.graphql_timeout use Gitlab::Graphql::Timeout, max_seconds: Gitlab.config.gitlab.graphql_timeout
    query_analyzer Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer.new # query_analyzer Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer.new
    query_analyzer Gitlab::Graphql::QueryAnalyzers::RecursionAnalyzer.new # query_analyzer Gitlab::Graphql::QueryAnalyzers::RecursionAnalyzer.new
    # query_analyzer Gitlab::Graphql::QueryAnalyzers::AST::LoggerAnalyzer query_analyzer Gitlab::Graphql::QueryAnalyzers::AST::LoggerAnalyzer
    # query_analyzer Gitlab::Graphql::QueryAnalyzers::AST::RecursionAnalyzer query_analyzer Gitlab::Graphql::QueryAnalyzers::AST::RecursionAnalyzer
    max_complexity DEFAULT_MAX_COMPLEXITY max_complexity DEFAULT_MAX_COMPLEXITY
    max_depth DEFAULT_MAX_DEPTH max_depth DEFAULT_MAX_DEPTH
    ......
    ...@@ -31,16 +31,16 @@ ...@@ -31,16 +31,16 @@
    context 'as a non-admin user' do context 'as a non-admin user' do
    let(:current_user) { user } let(:current_user) { user }
    it 'raises ResourceNotAvailable error' do it 'returns ResourceNotAvailable error' do
    expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end end
    end end
    context 'as an unauthenticated user' do context 'as an unauthenticated user' do
    let(:current_user) { nil } let(:current_user) { nil }
    it 'raises ResourceNotAvailable error' do it 'returns ResourceNotAvailable error' do
    expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end end
    end end
    ......
    ...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
    context 'when unauthorized' do context 'when unauthorized' do
    it 'raises an exception' do it 'raises an exception' do
    expect { resolve_blobs }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect(resolve_blobs).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end end
    end end
    ......
    ...@@ -40,10 +40,9 @@ ...@@ -40,10 +40,9 @@
    expect(result).to match_array([issue1]) expect(result).to match_array([issue1])
    end end
    it 'raises an exception if both assignee_username and assignee_wildcard_id are present' do it 'returns an exception if both assignee_username and assignee_wildcard_id are present' do
    expect do expect(resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } }))
    resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } }) .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    end end
    it 'accepts assignee wildcard id NONE' do it 'accepts assignee wildcard id NONE' do
    ......
    ...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
    end end
    it 'raises an argument error if list ID is not valid' do it 'raises an argument error if list ID is not valid' do
    expect { resolve_board_lists(args: { id: 'test' }) } expect(resolve_board_lists(args: { id: 'test' }))
    .to raise_error(Gitlab::Graphql::Errors::ArgumentError) .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end end
    end end
    end end
    ......
    ...@@ -23,9 +23,8 @@ ...@@ -23,9 +23,8 @@
    end end
    it 'requires an ID' do it 'requires an ID' do
    expect do expect(resolve(described_class, obj: board_parent, args: {}, ctx: { current_user: user }))
    resolve(described_class, obj: board_parent, args: {}, ctx: { current_user: user }) .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    end end
    context 'when querying for a single board' do context 'when querying for a single board' do
    ......
    ...@@ -54,10 +54,8 @@ ...@@ -54,10 +54,8 @@
    project.add_user(current_user, :developer) project.add_user(current_user, :developer)
    end end
    it 'raises error' do it 'returns error' do
    expect do expect(resolve_scope).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    resolve_scope
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end end
    end end
    end end
    ......
    ...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
    context 'when the user cannot see designs' do context 'when the user cannot see designs' do
    let(:current_user) { create(:user) } let(:current_user) { create(:user) }
    it 'raises ResourceNotAvailable' do it 'returns ResourceNotAvailable' do
    expect { resolve_design }.to raise_error(resource_not_available) expect(resolve_design).to be_instance_of(resource_not_available)
    end end
    end end
    ...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
    let(:global_id) { global_id_of(other_dav) } let(:global_id) { global_id_of(other_dav) }
    it 'raises ResourceNotAvailable' do it 'returns ResourceNotAvailable' do
    expect { resolve_design }.to raise_error(resource_not_available) expect(resolve_design).to be_instance_of(resource_not_available)
    end end
    context 'the current object does not constrain the issue' do context 'the current object does not constrain the issue' do
    ......
    ...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
    let(:args) { { id: GitlabSchema.id_from_object(first_design).to_s } } let(:args) { { id: GitlabSchema.id_from_object(first_design).to_s } }
    let(:gql_context) { { current_user: current_user } } let(:gql_context) { { current_user: current_user } }
    subject { resolve_design }
    before do before do
    project.add_developer(current_user) project.add_developer(current_user)
    end end
    ...@@ -35,15 +37,16 @@ ...@@ -35,15 +37,16 @@
    let(:gql_context) { { current_user: create(:user) } } let(:gql_context) { { current_user: create(:user) } }
    it 'returns nothing' do it 'returns nothing' do
    expect(resolve_design).to be_nil expect(subject).to be_nil
    end end
    end end
    context 'when no argument has been passed' do context 'when no argument has been passed' do
    let(:args) { {} } let(:args) { {} }
    it 'raises an error' do it 'returns an error' do
    expect { resolve_design }.to raise_error(::Gitlab::Graphql::Errors::ArgumentError, /must/) expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(subject.message).to match(/must/)
    end end
    end end
    ......
    ...@@ -109,14 +109,12 @@ ...@@ -109,14 +109,12 @@
    end end
    it 'returns an error if both project and author are provided' do it 'returns an error if both project and author are provided' do
    expect do args = {
    args = { author_id: current_user.to_global_id,
    author_id: current_user.to_global_id, project_id: project.to_global_id
    project_id: project.to_global_id }
    }
    resolve_snippets(args: args) expect(resolve_snippets(args: args)).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    end end
    end end
    end end
    ......
    ...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
    let_it_be(:timelog3) { create(:merge_request_timelog, merge_request: merge_request, spent_at: medium_time_ago) } let_it_be(:timelog3) { create(:merge_request_timelog, merge_request: merge_request, spent_at: medium_time_ago) }
    let(:args) { { start_time: short_time_ago, end_time: short_time_ago.noon } } let(:args) { { start_time: short_time_ago, end_time: short_time_ago.noon } }
    let(:timelogs) { resolve_timelogs(**args) }
    it 'finds all timelogs' do it 'finds all timelogs' do
    timelogs = resolve_timelogs timelogs = resolve_timelogs
    ...@@ -34,8 +35,6 @@ ...@@ -34,8 +35,6 @@
    end end
    it 'finds all timelogs within given dates' do it 'finds all timelogs within given dates' do
    timelogs = resolve_timelogs(**args)
    expect(timelogs).to contain_exactly(timelog1) expect(timelogs).to contain_exactly(timelog1)
    end end
    ...@@ -43,8 +42,6 @@ ...@@ -43,8 +42,6 @@
    let(:args) { { start_date: short_time_ago } } let(:args) { { start_date: short_time_ago } }
    it 'finds timelogs until the end of day of end_date' do it 'finds timelogs until the end of day of end_date' do
    timelogs = resolve_timelogs(**args)
    expect(timelogs).to contain_exactly(timelog1, timelog2) expect(timelogs).to contain_exactly(timelog1, timelog2)
    end end
    end end
    ...@@ -53,8 +50,6 @@ ...@@ -53,8 +50,6 @@
    let(:args) { { end_date: medium_time_ago } } let(:args) { { end_date: medium_time_ago } }
    it 'finds timelogs until the end of day of end_date' do it 'finds timelogs until the end of day of end_date' do
    timelogs = resolve_timelogs(**args)
    expect(timelogs).to contain_exactly(timelog3) expect(timelogs).to contain_exactly(timelog3)
    end end
    end end
    ...@@ -63,8 +58,6 @@ ...@@ -63,8 +58,6 @@
    let(:args) { { start_time: short_time_ago, end_date: short_time_ago } } let(:args) { { start_time: short_time_ago, end_date: short_time_ago } }
    it 'finds timelogs until the end of day of end_date' do it 'finds timelogs until the end of day of end_date' do
    timelogs = resolve_timelogs(**args)
    expect(timelogs).to contain_exactly(timelog1, timelog2) expect(timelogs).to contain_exactly(timelog1, timelog2)
    end end
    end end
    ...@@ -73,8 +66,6 @@ ...@@ -73,8 +66,6 @@
    let(:args) { { start_date: short_time_ago, end_time: short_time_ago.noon } } let(:args) { { start_date: short_time_ago, end_time: short_time_ago.noon } }
    it 'finds all timelogs within start_date and end_time' do it 'finds all timelogs within start_date and end_time' do
    timelogs = resolve_timelogs(**args)
    expect(timelogs).to contain_exactly(timelog1) expect(timelogs).to contain_exactly(timelog1)
    end end
    end end
    ...@@ -86,8 +77,8 @@ ...@@ -86,8 +77,8 @@
    let(:args) { { start_time: short_time_ago, start_date: short_time_ago } } let(:args) { { start_time: short_time_ago, start_date: short_time_ago } }
    it 'returns correct error' do it 'returns correct error' do
    expect { resolve_timelogs(**args) } expect(timelogs).to be_instance_of(error_class)
    .to raise_error(error_class, /Provide either a start date or time, but not both/) expect(timelogs.message).to eq 'Provide either a start date or time, but not both'
    end end
    end end
    ...@@ -95,8 +86,8 @@ ...@@ -95,8 +86,8 @@
    let(:args) { { end_time: short_time_ago, end_date: short_time_ago } } let(:args) { { end_time: short_time_ago, end_date: short_time_ago } }
    it 'returns correct error' do it 'returns correct error' do
    expect { resolve_timelogs(**args) } expect(timelogs).to be_instance_of(error_class)
    .to raise_error(error_class, /Provide either an end date or time, but not both/) expect(timelogs.message).to eq 'Provide either an end date or time, but not both'
    end end
    end end
    ...@@ -104,8 +95,8 @@ ...@@ -104,8 +95,8 @@
    let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } } let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } }
    it 'returns correct error' do it 'returns correct error' do
    expect { resolve_timelogs(**args) } expect(timelogs).to be_instance_of(error_class)
    .to raise_error(error_class, /Start argument must be before End argument/) expect(timelogs.message).to eq 'Start argument must be before End argument'
    end end
    end end
    end end
    ......
    ...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
    subject { batch_sync { resolve_user_discussions_count(private_issue) } } subject { batch_sync { resolve_user_discussions_count(private_issue) } }
    it 'returns no discussions' do it 'returns no discussions' do
    expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end end
    end end
    end end
    ......
    ...@@ -9,15 +9,14 @@ ...@@ -9,15 +9,14 @@
    let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
    context 'when neither an ID or a username is provided' do context 'when neither an ID or a username is provided' do
    it 'raises an ArgumentError' do it 'returns an ArgumentError' do
    expect { resolve_user } expect(resolve_user).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    end end
    end end
    it 'raises an ArgumentError when both an ID and username are provided' do it 'returns an ArgumentError when both an ID and username are provided' do
    expect { resolve_user(id: user.to_global_id, username: user.username) } expect(resolve_user(id: user.to_global_id, username: user.username))
    .to raise_error(Gitlab::Graphql::Errors::ArgumentError) .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end end
    context 'by username' do context 'by username' do
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment