2020-04-04 14:09:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Resolvers::EnvironmentsResolver do
|
2020-04-04 14:09:53 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
context "with a group" do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, :public, group: group) }
|
2020-04-07 20:09:30 -04:00
|
|
|
let!(:environment1) { create(:environment, :available, name: 'production', project: project) }
|
|
|
|
let!(:environment2) { create(:environment, :stopped, name: 'test', project: project) }
|
|
|
|
let!(:environment3) { create(:environment, :available, name: 'test2', project: project) }
|
2020-04-04 14:09:53 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
it 'finds all environments' do
|
|
|
|
expect(resolve_environments).to contain_exactly(environment1, environment2, environment3)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with name' do
|
|
|
|
it 'finds a specific environment with name' do
|
|
|
|
expect(resolve_environments(name: environment1.name)).to contain_exactly(environment1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with search' do
|
|
|
|
it 'searches environment by name' do
|
|
|
|
expect(resolve_environments(search: 'test')).to contain_exactly(environment2, environment3)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the search term does not match any environments' do
|
|
|
|
it 'is empty' do
|
|
|
|
expect(resolve_environments(search: 'nonsense')).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-07 20:09:30 -04:00
|
|
|
context 'with states' do
|
|
|
|
it 'searches environments by state' do
|
|
|
|
expect(resolve_environments(states: ['available'])).to contain_exactly(environment1, environment3)
|
|
|
|
end
|
|
|
|
|
2022-03-14 05:08:52 -04:00
|
|
|
it 'generates an error if requested state is invalid' do
|
|
|
|
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
|
|
|
|
resolve_environments(states: ['invalid'])
|
|
|
|
end
|
2020-04-07 20:09:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-04 14:09:53 -04:00
|
|
|
context 'when project is nil' do
|
|
|
|
subject { resolve(described_class, obj: nil, args: {}, ctx: { current_user: current_user }) }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_environments(args = {}, context = { current_user: current_user })
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: context)
|
|
|
|
end
|
|
|
|
end
|