Commit ebe40f45 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC Committed by Luke Duncalfe

Fix `errors` attribute of ScanType on GraphQL

parent 09580cb6
......@@ -3,6 +3,8 @@
module Types
# rubocop: disable Graphql/AuthorizeTypes
class ScanType < BaseObject
present_using ::Security::ScanPresenter
graphql_name 'Scan'
description 'Represents the security scan information'
......@@ -10,9 +12,5 @@ module Types
field :name, GraphQL::STRING_TYPE, null: false, description: 'Name of the scan.'
field :errors, [GraphQL::STRING_TYPE], null: false, description: 'List of errors.'
def errors
object.info['errors'].to_a
end
end
end
# frozen_string_literal: true
module Security
class ScanPresenter < Gitlab::View::Presenter::Delegated
ERROR_MESSAGE_FORMAT = '[%<type>s] %<message>s'
presents :scan
def errors
info['errors'].to_a.map { |error| format(ERROR_MESSAGE_FORMAT, error.symbolize_keys) }
end
end
end
---
title: Fix the 'errors' attribute of the 'ScanType' on GraphQL API
merge_request: 57882
author:
type: fixed
......@@ -3,8 +3,40 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['Scan'] do
include GraphqlHelpers
let(:fields) { %i(name errors) }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_scan) }
describe 'field values' do
let_it_be(:build) { create(:ee_ci_build, :dast, name: 'foo') }
let_it_be(:security_scan) { build.security_scans.first }
let_it_be(:user) { create(:user) }
subject { resolve_field(field_name, security_scan, current_user: user) }
before do
stub_licensed_features(security_dashboard: true)
build.project.add_developer(user)
end
describe 'name' do
let(:field_name) { :name }
it { is_expected.to eq('foo') }
end
describe 'errors' do
let(:field_name) { :errors }
before do
security_scan.update!(info: { 'errors' => [{ 'type' => 'foo', 'message' => 'bar' }] })
end
it { is_expected.to eq(['[foo] bar']) }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Security::ScanPresenter do
let(:presenter) { described_class.new(security_scan) }
let(:security_scan) { build_stubbed(:security_scan, info: { 'errors' => [{ 'type' => 'foo', 'message' => 'bar' }] }) }
describe '#errors' do
subject { presenter.errors }
it { is_expected.to eq(['[foo] bar']) }
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