2016-11-16 08:56:30 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state do
|
2016-11-16 08:56:30 -05:00
|
|
|
describe '#execute' do
|
|
|
|
let(:service) { create(:service) }
|
|
|
|
|
|
|
|
subject { described_class.new(service, params).execute }
|
|
|
|
|
|
|
|
context 'find user mapping' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:chat_name) { create(:chat_name, user: user, service: service) }
|
|
|
|
|
|
|
|
context 'when existing user is requested' do
|
|
|
|
let(:params) { { team_id: chat_name.team_id, user_id: chat_name.chat_id } }
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
it 'returns the existing chat_name' do
|
|
|
|
is_expected.to eq(chat_name)
|
2016-11-16 08:56:30 -05:00
|
|
|
end
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
it 'updates the last used timestamp if one is not already set' do
|
2017-03-29 03:44:44 -04:00
|
|
|
expect(chat_name.last_used_at).to be_nil
|
|
|
|
|
2016-11-16 08:56:30 -05:00
|
|
|
subject
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
expect(chat_name.reload.last_used_at).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only updates an existing timestamp once within a certain time frame' do
|
|
|
|
service = described_class.new(service, params)
|
|
|
|
|
|
|
|
expect(chat_name.last_used_at).to be_nil
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
time = chat_name.reload.last_used_at
|
2017-03-29 03:44:44 -04:00
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
service.execute
|
2017-03-29 03:44:44 -04:00
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
expect(chat_name.reload.last_used_at).to eq(time)
|
2016-11-16 08:56:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when different user is requested' do
|
|
|
|
let(:params) { { team_id: chat_name.team_id, user_id: 'non-existing-user' } }
|
|
|
|
|
|
|
|
it 'returns existing user' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|