Commit de7db217 authored by Felipe Artur's avatar Felipe Artur

Allow to filter requirements with missing status

Filter requirements without test reports on GraphQL
parent 375a76af
...@@ -5661,6 +5661,16 @@ State of a requirement. ...@@ -5661,6 +5661,16 @@ State of a requirement.
| `ARCHIVED` | | | `ARCHIVED` | |
| `OPENED` | | | `OPENED` | |
### RequirementStatusFilter
Status of a requirement based on last test report.
| Value | Description |
| ----- | ----------- |
| `FAILED` | |
| `MISSING` | Requirements without any test report. |
| `PASSED` | |
### SastUiComponentSize ### SastUiComponentSize
Size of UI component in SAST configuration page. Size of UI component in SAST configuration page.
......
...@@ -62,7 +62,11 @@ module RequirementsManagement ...@@ -62,7 +62,11 @@ module RequirementsManagement
def by_last_test_report_state(items) def by_last_test_report_state(items)
return items unless params[:last_test_report_state] return items unless params[:last_test_report_state]
items.with_last_test_report_state(params[:last_test_report_state]) if params[:last_test_report_state] == 'missing'
items.without_test_reports
else
items.with_last_test_report_state(params[:last_test_report_state])
end
end end
def get_authors(username_param) def get_authors(username_param)
......
...@@ -16,7 +16,7 @@ module Resolvers ...@@ -16,7 +16,7 @@ module Resolvers
required: false, required: false,
description: 'List of IIDs of requirements, e.g., [1, 2].' description: 'List of IIDs of requirements, e.g., [1, 2].'
argument :last_test_report_state, ::Types::RequirementsManagement::TestReportStateEnum, argument :last_test_report_state, ::Types::RequirementsManagement::RequirementStatusFilterEnum,
required: false, required: false,
description: 'The state of latest requirement test report.' description: 'The state of latest requirement test report.'
......
# frozen_string_literal: true
module Types
module RequirementsManagement
class RequirementStatusFilterEnum < TestReportStateEnum
graphql_name 'RequirementStatusFilter'
description 'Status of a requirement based on last test report'
value 'MISSING', value: 'missing', description: 'Requirements without any test report.'
end
end
end
...@@ -53,6 +53,10 @@ module RequirementsManagement ...@@ -53,6 +53,10 @@ module RequirementsManagement
include_last_test_report_with_state.where( test_reports: { state: state } ) include_last_test_report_with_state.where( test_reports: { state: state } )
end end
scope :without_test_reports, -> do
left_joins(:test_reports).where(requirements_management_test_reports: { requirement_id: nil })
end
class << self class << self
# Searches for records with a matching title. # Searches for records with a matching title.
# #
......
---
title: Allow to filter requirements by missing status
merge_request: 54711
author:
type: added
...@@ -42,13 +42,25 @@ RSpec.describe Resolvers::RequirementsManagement::RequirementsResolver do ...@@ -42,13 +42,25 @@ RSpec.describe Resolvers::RequirementsManagement::RequirementsResolver do
expect(resolve_requirements(iids: [requirement1.iid, requirement3.iid])).to contain_exactly(requirement1, requirement3) expect(resolve_requirements(iids: [requirement1.iid, requirement3.iid])).to contain_exactly(requirement1, requirement3)
end end
it 'filters by last test report state' do context 'when filtering by last test report state' do
create(:test_report, state: :failed) before do
create(:test_report, requirement: requirement1, state: :passed) create(:test_report, state: :failed)
create(:test_report, requirement: requirement1, state: :failed) create(:test_report, requirement: requirement1, state: :passed)
create(:test_report, requirement: requirement3, state: :failed) create(:test_report, requirement: requirement1, state: :failed)
create(:test_report, requirement: requirement3, state: :passed)
end
it 'filters by failed requirements' do
expect(resolve_requirements(last_test_report_state: 'failed')).to contain_exactly(requirement1)
end
expect(resolve_requirements(last_test_report_state: 'failed')).to contain_exactly(requirement1, requirement3) it 'filters by passed requirements' do
expect(resolve_requirements(last_test_report_state: 'passed')).to contain_exactly(requirement3)
end
it 'filters requirements without test reports' do
expect(resolve_requirements(last_test_report_state: 'missing')).to contain_exactly(requirement2)
end
end end
describe 'sorting' do describe 'sorting' do
......
...@@ -106,6 +106,19 @@ RSpec.describe RequirementsManagement::Requirement do ...@@ -106,6 +106,19 @@ RSpec.describe RequirementsManagement::Requirement do
end end
end end
describe '.without_test_reports' do
let_it_be(:requirement1) { create(:requirement) }
let_it_be(:requirement2) { create(:requirement) }
before do
create(:test_report, requirement: requirement2, state: :passed)
end
it 'returns requirements without test reports' do
expect(described_class.without_test_reports).to contain_exactly(requirement1)
end
end
describe '#last_test_report_state' do describe '#last_test_report_state' do
let_it_be(:requirement) { create(:requirement) } let_it_be(:requirement) { create(:requirement) }
......
...@@ -169,6 +169,17 @@ RSpec.describe 'getting a requirement list for a project' do ...@@ -169,6 +169,17 @@ RSpec.describe 'getting a requirement list for a project' do
match_single_result(requirement1) match_single_result(requirement1)
end end
context 'for MISSING status' do
let_it_be(:requirement3) { create(:requirement, project: filter_project, author: other_user, title: 'need test report') }
let(:params) { '(lastTestReportState: MISSING)' }
it 'returns filtered requirements' do
expect(graphql_errors).to be_nil
match_single_result(requirement3)
end
end
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