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

45 lines
1.2 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Resolvers::GroupsResolver, feature_category: :subgroups do
2021-10-27 15:23:28 +05:30
include GraphqlHelpers
describe '#resolve' do
let_it_be(:user) { create(:user) }
2023-04-23 21:23:45 +05:30
let_it_be(:public_group) { create(:group, name: 'public-group') }
let_it_be(:private_group) { create(:group, :private, name: 'private-group') }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
let(:params) { {} }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
subject { resolve(described_class, args: params, ctx: { current_user: user }) }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
it 'includes public groups' do
expect(subject).to contain_exactly(public_group)
2021-10-27 15:23:28 +05:30
end
2023-04-23 21:23:45 +05:30
it 'includes accessible private groups' do
private_group.add_developer(user)
expect(subject).to contain_exactly(public_group, private_group)
2021-10-27 15:23:28 +05:30
end
2023-04-23 21:23:45 +05:30
describe 'ordering' do
let_it_be(:other_group) { create(:group, name: 'other-group') }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
it 'orders by name ascending' do
expect(subject.map(&:name)).to eq(%w[other-group public-group])
2021-10-27 15:23:28 +05:30
end
end
2023-04-23 21:23:45 +05:30
context 'with `search` argument' do
let_it_be(:other_group) { create(:group, name: 'other-group') }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
let(:params) { { search: 'oth' } }
2021-10-27 15:23:28 +05:30
2023-04-23 21:23:45 +05:30
it 'filters groups by name' do
expect(subject).to contain_exactly(other_group)
2021-10-27 15:23:28 +05:30
end
end
end
end