debian-mirror-gitlab/spec/services/chat_names/find_user_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state, feature_category: :user_profile do
2017-08-17 22:00:37 +05:30
describe '#execute' do
2023-03-04 22:38:38 +05:30
subject { described_class.new(team_id, user_id).execute }
2017-08-17 22:00:37 +05:30
context 'find user mapping' do
2023-03-04 22:38:38 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:chat_name) { create(:chat_name, user: user) }
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
let(:team_id) { chat_name.team_id }
let(:user_id) { chat_name.chat_id }
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
context 'when existing user is requested' do
2018-03-27 19:54:05 +05:30
it 'returns the existing chat_name' do
is_expected.to eq(chat_name)
2017-08-17 22:00:37 +05:30
end
2018-03-27 19:54:05 +05:30
it 'updates the last used timestamp if one is not already set' do
2017-08-17 22:00:37 +05:30
expect(chat_name.last_used_at).to be_nil
subject
2018-03-27 19:54:05 +05:30
expect(chat_name.reload.last_used_at).to be_present
end
it 'only updates an existing timestamp once within a certain time frame' do
2023-03-04 22:38:38 +05:30
chat_name = create(:chat_name, user: user)
service = described_class.new(team_id, user_id)
2018-03-27 19:54:05 +05:30
expect(chat_name.last_used_at).to be_nil
service.execute
time = chat_name.reload.last_used_at
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
service.execute
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
expect(chat_name.reload.last_used_at).to eq(time)
2017-08-17 22:00:37 +05:30
end
end
context 'when different user is requested' do
2023-03-04 22:38:38 +05:30
let(:user_id) { 'non-existing-user' }
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
it 'returns nil' do
2017-08-17 22:00:37 +05:30
is_expected.to be_nil
end
end
end
end
end