2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2018-01-25 07:26:52 -05:00
|
|
|
|
|
|
|
describe Gitlab::Checks::ProjectCreated, :clean_gitlab_redis_shared_state do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
describe '.fetch_message' do
|
2018-01-25 07:26:52 -05:00
|
|
|
context 'with a project created message queue' do
|
2018-01-26 09:28:08 -05:00
|
|
|
let(:project_created) { described_class.new(project, user, 'http') }
|
2018-01-25 07:26:52 -05:00
|
|
|
|
|
|
|
before do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_created.add_message
|
2018-01-25 07:26:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project created message' do
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(described_class.fetch_message(user.id, project.id)).to eq(project_created.message)
|
2018-01-25 07:26:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes the project created message from redis' do
|
|
|
|
expect(Gitlab::Redis::SharedState.with { |redis| redis.get("project_created:#{user.id}:#{project.id}") }).not_to be_nil
|
2018-01-26 09:28:08 -05:00
|
|
|
described_class.fetch_message(user.id, project.id)
|
2018-01-25 07:26:52 -05:00
|
|
|
expect(Gitlab::Redis::SharedState.with { |redis| redis.get("project_created:#{user.id}:#{project.id}") }).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no project created message queue' do
|
|
|
|
it 'returns nil' do
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(described_class.fetch_message(1, 2)).to be_nil
|
2018-01-25 07:26:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
describe '#add_message' do
|
2018-01-25 07:26:52 -05:00
|
|
|
it 'queues a project created message' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_created = described_class.new(project, user, 'http')
|
2018-01-25 07:26:52 -05:00
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(project_created.add_message).to eq('OK')
|
2018-01-25 07:26:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles anonymous push' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_created = described_class.new(nil, user, 'http')
|
2018-01-25 07:26:52 -05:00
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(project_created.add_message).to be_nil
|
2018-01-25 07:26:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|