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

84 lines
2.7 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::ReleasesResolver 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 } }
2020-05-24 23:13:21 +05:30
before do
project.add_developer(developer)
end
describe '#resolve' do
context 'when the user does not have access to the project' do
let(:current_user) { public_user }
it 'returns an empty array' do
expect(resolve_releases).to eq([])
end
end
context "when the user has full access to the project's releases" do
let(:current_user) { developer }
it 'returns all releases associated to the project' do
2021-01-29 00:20:46 +05:30
expect(resolve_releases).to eq([release_v3, release_v2, release_v1])
end
describe 'sorting behavior' do
context 'with sort: :released_at_desc' do
let(:args) { { sort: :released_at_desc } }
it 'returns the releases ordered by released_at in descending order' do
expect(resolve_releases).to eq([release_v3, release_v2, release_v1])
end
end
context 'with sort: :released_at_asc' do
let(:args) { { sort: :released_at_asc } }
it 'returns the releases ordered by released_at in ascending order' do
expect(resolve_releases).to eq([release_v1, release_v2, release_v3])
end
end
context 'with sort: :created_desc' do
let(:args) { { sort: :created_desc } }
it 'returns the releases ordered by created_at in descending order' do
expect(resolve_releases).to eq([release_v1, release_v3, release_v2])
end
end
context 'with sort: :created_asc' do
let(:args) { { sort: :created_asc } }
it 'returns the releases ordered by created_at in ascending order' do
expect(resolve_releases).to eq([release_v2, release_v3, release_v1])
end
end
2020-05-24 23:13:21 +05:30
end
end
end
private
def resolve_releases
context = { current_user: current_user }
2021-01-29 00:20:46 +05:30
resolve(described_class, obj: project, args: args, ctx: context)
2020-05-24 23:13:21 +05:30
end
end