summaryrefslogtreecommitdiff
path: root/spec/services/chat_names/find_user_service_spec.rb
blob: 51441e8f3bec2f0249de2d17453d50ff5598ef6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'spec_helper'

describe ChatNames::FindUserService, services: true do
  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 } }

        it 'returns the existing user' do
          is_expected.to eq(user)
        end

        it 'updates when last time chat name was used' do
          subject

          expect(chat_name.reload.last_used_at).to be_like_time(Time.now)
        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