debian-mirror-gitlab/spec/graphql/resolvers/releases_resolver_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.9 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Resolvers::ReleasesResolver, feature_category: :release_orchestration do
2020-05-24 23:13:21 +05:30
include GraphqlHelpers
2021-01-29 00:20:46 +05:30
let_it_be(:today) { Time.now }
let_it_be(:yesterday) { today - 1.day }
let_it_be(:tomorrow) { today + 1.day }
2020-05-24 23:13:21 +05:30
let_it_be(:project) { create(:project, :private) }
2021-01-29 00:20:46 +05:30
let_it_be(:release_v1) { create(:release, project: project, tag: 'v1.0.0', released_at: yesterday, created_at: tomorrow) }
let_it_be(:release_v2) { create(:release, project: project, tag: 'v2.0.0', released_at: today, created_at: yesterday) }
let_it_be(:release_v3) { create(:release, project: project, tag: 'v3.0.0', released_at: tomorrow, created_at: today) }
2020-05-24 23:13:21 +05:30
let_it_be(:developer) { create(:user) }
let_it_be(:public_user) { create(:user) }
2021-01-29 00:20:46 +05:30
let(:args) { { sort: :released_at_desc } }
2021-02-22 17:27:13 +05:30
let(:all_releases) { [release_v1, release_v2, release_v3] }
2021-01-29 00:20:46 +05:30
2020-05-24 23:13:21 +05:30
before do
project.add_developer(developer)
end
describe '#resolve' do
2023-04-23 21:23:45 +05:30
it_behaves_like 'releases and group releases resolver'
2020-05-24 23:13:21 +05:30
2023-04-23 21:23:45 +05:30
describe 'when order_by is created_at' do
2020-05-24 23:13:21 +05:30
let(:current_user) { developer }
2023-04-23 21:23:45 +05:30
context 'with sort: desc' do
let(:args) { { sort: :created_desc } }
2021-01-29 00:20:46 +05:30
2023-04-23 21:23:45 +05:30
it 'returns the releases ordered by created_at in descending order' do
expect(resolve_releases.to_a)
.to match_array(all_releases)
.and be_sorted(:created_at, :desc)
2021-01-29 00:20:46 +05:30
end
2023-04-23 21:23:45 +05:30
end
2021-01-29 00:20:46 +05:30
2023-04-23 21:23:45 +05:30
context 'with sort: asc' do
let(:args) { { sort: :created_asc } }
2021-01-29 00:20:46 +05:30
2023-04-23 21:23:45 +05:30
it 'returns the releases ordered by created_at in ascending order' do
expect(resolve_releases.to_a)
.to match_array(all_releases)
.and be_sorted(:created_at, :asc)
2021-01-29 00:20:46 +05:30
end
2020-05-24 23:13:21 +05:30
end
end
end
private
def resolve_releases
context = { current_user: current_user }
2022-07-23 23:45:48 +05:30
resolve(described_class, obj: project, args: args, ctx: context, arg_style: :internal)
2020-05-24 23:13:21 +05:30
end
end