Commit 080efbba authored by Felipe Artur's avatar Felipe Artur

Alow to filter epics by different params

Adds support for label, author, title, state,
sort, and description filters in epic fetch query.
parent 299a9311
...@@ -14,6 +14,22 @@ module Resolvers ...@@ -14,6 +14,22 @@ module Resolvers
required: false, required: false,
description: 'Filter epics by state' description: 'Filter epics by state'
argument :search, GraphQL::STRING_TYPE,
required: false,
description: 'Filter epics by title and description'
argument :sort, Types::EpicSortEnum,
required: false,
description: 'List epics by sort order'
argument :author_username, GraphQL::STRING_TYPE,
required: false,
description: 'List epics for author'
argument :label_name, [GraphQL::STRING_TYPE],
required: false,
description: 'List epics that has given label names'
argument :start_date, Types::TimeType, argument :start_date, Types::TimeType,
required: false, required: false,
description: 'List epics within a time frame where epics.start_date is between start_date and end_date parameters (end_date parameter must be present)' description: 'List epics within a time frame where epics.start_date is between start_date and end_date parameters (end_date parameter must be present)'
......
# frozen_string_literal: true
module Types
class EpicSortEnum < BaseEnum
graphql_name 'EpicSort'
description 'Roadmap sort values'
value 'start_date_desc', 'Start date at descending order'
value 'start_date_asc', 'Start date at ascending order'
value 'end_date_desc', 'End date at descending order'
value 'end_date_asc', 'End date at ascending order'
end
end
...@@ -102,6 +102,80 @@ describe Resolvers::EpicResolver do ...@@ -102,6 +102,80 @@ describe Resolvers::EpicResolver do
end end
end end
context 'with search' do
let!(:epic1) { create(:epic, group: group, title: 'first created', description: 'description') }
let!(:epic2) { create(:epic, group: group, title: 'second created', description: 'text 1') }
let!(:epic3) { create(:epic, group: group, title: 'third', description: 'text 2') }
it 'filters epics by title' do
epics = resolve_epics(search: 'created')
expect(epics).to match_array([epic1, epic2])
end
it 'filters epics by description' do
epics = resolve_epics(search: 'text')
expect(epics).to match_array([epic2, epic3])
end
end
context 'with author_username' do
it 'filters epics by author' do
user = create(:user)
epic = create(:epic, group: group, author: user )
create(:epic, group: group)
epics = resolve_epics(author_username: user.username)
expect(epics).to match_array([epic])
end
end
context 'with label_name' do
it 'filters epics by labels' do
label_1 = create(:group_label, group: group)
label_2 = create(:group_label, group: group)
epic_1 = create(:labeled_epic, group: group, labels: [label_1, label_2])
create(:labeled_epic, group: group, labels: [label_1])
create(:labeled_epic, group: group)
epics = resolve_epics(label_name: [label_1.title, label_2.title])
expect(epics).to match_array([epic_1])
end
end
context 'with sort' do
let!(:epic1) { create(:epic, group: group, title: 'first created', description: 'description', start_date: 10.days.ago, end_date: 10.days.from_now) }
let!(:epic2) { create(:epic, group: group, title: 'second created', description: 'text 1', start_date: 20.days.ago, end_date: 20.days.from_now) }
let!(:epic3) { create(:epic, group: group, title: 'third', description: 'text 2', start_date: 30.days.ago, end_date: 30.days.from_now) }
it 'orders epics by start date in descending order' do
epics = resolve_epics(sort: 'start_date_desc')
expect(epics).to match_array([epic3, epic2, epic1])
end
it 'orders epics by start date in ascending order' do
epics = resolve_epics(sort: 'start_date_asc')
expect(epics).to match_array([epic1, epic2, epic3])
end
it 'orders epics by end date in descending order' do
epics = resolve_epics(sort: 'start_date_asc')
expect(epics).to match_array([epic1, epic2, epic3])
end
it 'orders epics by end date in ascending order' do
epics = resolve_epics(sort: 'start_date_asc')
expect(epics).to match_array([epic3, epic2, epic1])
end
end
context 'with subgroups' do context 'with subgroups' do
let(:sub_group) { create(:group, parent: group) } let(:sub_group) { create(:group, parent: group) }
let(:iids) { [epic1, epic2].map(&:iid) } let(:iids) { [epic1, epic2].map(&:iid) }
......
# frozen_string_literal: true
require 'spec_helper'
describe GitlabSchema.types['EpicSort'] do
it { expect(described_class.graphql_name).to eq('EpicSort') }
it 'exposes all the existing epic sort orders' do
expect(described_class.values.keys).to include(*%w[start_date_desc start_date_asc end_date_desc end_date_asc])
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