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