diff options
author | Robert Speicher <rspeicher@gmail.com> | 2019-02-21 22:55:14 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2019-02-21 22:55:14 +0300 |
commit | 1f4e5fe7b191211520f2a0f415a34dac641326a7 (patch) | |
tree | 5e609cdfe76a04b743c2273f601313ae744f304b /spec | |
parent | 0b846d7c550827795918c5b43ffc2d8709a2c4c7 (diff) | |
parent | 87dfe5a27a51c722bbeaa4582168f1277a0df034 (diff) |
Merge branch '56492-implement-new-arguments-state-closed_before-and-closed_after-for-issuesresolver-in-graphql' into 'master'
Implement new arguments `state`, `closed_before` and `closed_after` for `IssuesResolver` in GraphQL
Closes #56492
See merge request gitlab-org/gitlab-ce!24910
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/issues_finder_spec.rb | 30 | ||||
-rw-r--r-- | spec/graphql/resolvers/issues_resolver_spec.rb | 69 | ||||
-rw-r--r-- | spec/graphql/types/issuable_state_enum_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/issue_state_enum_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/merge_request_state_enum_spec.rb | 13 | ||||
-rw-r--r-- | spec/support/shared_examples/graphql/issuable_state_shared_examples.rb | 5 |
6 files changed, 124 insertions, 11 deletions
diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 34cb09942be..fe8000e419b 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -416,6 +416,36 @@ describe IssuesFinder do end end + context 'filtering by closed_at' do + let!(:closed_issue1) { create(:issue, project: project1, state: :closed, closed_at: 1.week.ago) } + let!(:closed_issue2) { create(:issue, project: project2, state: :closed, closed_at: 1.week.from_now) } + let!(:closed_issue3) { create(:issue, project: project2, state: :closed, closed_at: 2.weeks.from_now) } + + context 'through closed_after' do + let(:params) { { state: :closed, closed_after: closed_issue3.closed_at } } + + it 'returns issues closed on or after the given date' do + expect(issues).to contain_exactly(closed_issue3) + end + end + + context 'through closed_before' do + let(:params) { { state: :closed, closed_before: closed_issue1.closed_at } } + + it 'returns issues closed on or before the given date' do + expect(issues).to contain_exactly(closed_issue1) + end + end + + context 'through closed_after and closed_before' do + let(:params) { { state: :closed, closed_after: closed_issue2.closed_at, closed_before: closed_issue3.closed_at } } + + it 'returns issues closed between the given dates' do + expect(issues).to contain_exactly(closed_issue2, closed_issue3) + end + end + end + context 'filtering by reaction name' do context 'user searches by no reaction' do let(:params) { { my_reaction_emoji: 'None' } } diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index 66de372e9fe..5f9c180cbb7 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -5,16 +5,63 @@ describe Resolvers::IssuesResolver do let(:current_user) { create(:user) } set(:project) { create(:project) } - set(:issue) { create(:issue, project: project) } - set(:issue2) { create(:issue, project: project, title: 'foo') } + set(:issue1) { create(:issue, project: project, state: :opened, created_at: 3.hours.ago, updated_at: 3.hours.ago) } + set(:issue2) { create(:issue, project: project, state: :closed, title: 'foo', created_at: 1.hour.ago, updated_at: 1.hour.ago, closed_at: 1.hour.ago) } + set(:label1) { create(:label, project: project) } + set(:label2) { create(:label, project: project) } before do project.add_developer(current_user) + create(:label_link, label: label1, target: issue1) + create(:label_link, label: label1, target: issue2) + create(:label_link, label: label2, target: issue2) end describe '#resolve' do it 'finds all issues' do - expect(resolve_issues).to contain_exactly(issue, issue2) + expect(resolve_issues).to contain_exactly(issue1, issue2) + end + + it 'filters by state' do + expect(resolve_issues(state: 'opened')).to contain_exactly(issue1) + expect(resolve_issues(state: 'closed')).to contain_exactly(issue2) + end + + it 'filters by labels' do + expect(resolve_issues(label_name: [label1.title])).to contain_exactly(issue1, issue2) + expect(resolve_issues(label_name: [label1.title, label2.title])).to contain_exactly(issue2) + end + + describe 'filters by created_at' do + it 'filters by created_before' do + expect(resolve_issues(created_before: 2.hours.ago)).to contain_exactly(issue1) + end + + it 'filters by created_after' do + expect(resolve_issues(created_after: 2.hours.ago)).to contain_exactly(issue2) + end + end + + describe 'filters by updated_at' do + it 'filters by updated_before' do + expect(resolve_issues(updated_before: 2.hours.ago)).to contain_exactly(issue1) + end + + it 'filters by updated_after' do + expect(resolve_issues(updated_after: 2.hours.ago)).to contain_exactly(issue2) + end + end + + describe 'filters by closed_at' do + let!(:issue3) { create(:issue, project: project, state: :closed, closed_at: 3.hours.ago) } + + it 'filters by closed_before' do + expect(resolve_issues(closed_before: 2.hours.ago)).to contain_exactly(issue3) + end + + it 'filters by closed_after' do + expect(resolve_issues(closed_after: 2.hours.ago)).to contain_exactly(issue2) + end end it 'searches issues' do @@ -22,7 +69,7 @@ describe Resolvers::IssuesResolver do end it 'sort issues' do - expect(resolve_issues(sort: 'created_desc')).to eq [issue2, issue] + expect(resolve_issues(sort: 'created_desc')).to eq [issue2, issue1] end it 'returns issues user can see' do @@ -30,31 +77,31 @@ describe Resolvers::IssuesResolver do create(:issue, confidential: true) - expect(resolve_issues).to contain_exactly(issue, issue2) + expect(resolve_issues).to contain_exactly(issue1, issue2) end it 'finds a specific issue with iid' do - expect(resolve_issues(iid: issue.iid)).to contain_exactly(issue) + expect(resolve_issues(iid: issue1.iid)).to contain_exactly(issue1) end it 'finds a specific issue with iids' do - expect(resolve_issues(iids: issue.iid)).to contain_exactly(issue) + expect(resolve_issues(iids: issue1.iid)).to contain_exactly(issue1) end it 'finds multiple issues with iids' do - expect(resolve_issues(iids: [issue.iid, issue2.iid])) - .to contain_exactly(issue, issue2) + expect(resolve_issues(iids: [issue1.iid, issue2.iid])) + .to contain_exactly(issue1, issue2) end it 'finds only the issues within the project we are looking at' do another_project = create(:project) - iids = [issue, issue2].map(&:iid) + iids = [issue1, issue2].map(&:iid) iids.each do |iid| create(:issue, project: another_project, iid: iid) end - expect(resolve_issues(iids: iids)).to contain_exactly(issue, issue2) + expect(resolve_issues(iids: iids)).to contain_exactly(issue1, issue2) end end diff --git a/spec/graphql/types/issuable_state_enum_spec.rb b/spec/graphql/types/issuable_state_enum_spec.rb new file mode 100644 index 00000000000..65a80fa4176 --- /dev/null +++ b/spec/graphql/types/issuable_state_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['IssuableState'] do + it { expect(described_class.graphql_name).to eq('IssuableState') } + + it_behaves_like 'issuable state' +end diff --git a/spec/graphql/types/issue_state_enum_spec.rb b/spec/graphql/types/issue_state_enum_spec.rb new file mode 100644 index 00000000000..de19e6fc505 --- /dev/null +++ b/spec/graphql/types/issue_state_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['IssueState'] do + it { expect(described_class.graphql_name).to eq('IssueState') } + + it_behaves_like 'issuable state' +end diff --git a/spec/graphql/types/merge_request_state_enum_spec.rb b/spec/graphql/types/merge_request_state_enum_spec.rb new file mode 100644 index 00000000000..626e33b18d3 --- /dev/null +++ b/spec/graphql/types/merge_request_state_enum_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['MergeRequestState'] do + it { expect(described_class.graphql_name).to eq('MergeRequestState') } + + it_behaves_like 'issuable state' + + it 'exposes all the existing merge request states' do + expect(described_class.values.keys).to include('merged') + end +end diff --git a/spec/support/shared_examples/graphql/issuable_state_shared_examples.rb b/spec/support/shared_examples/graphql/issuable_state_shared_examples.rb new file mode 100644 index 00000000000..713f0a879c1 --- /dev/null +++ b/spec/support/shared_examples/graphql/issuable_state_shared_examples.rb @@ -0,0 +1,5 @@ +RSpec.shared_examples 'issuable state' do + it 'exposes all the existing issuable states' do + expect(described_class.values.keys).to include(*%w[opened closed locked]) + end +end |