2020-05-04 17:37:56 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
let(:web_widget) { create(:channel_widget, account: account) }
|
|
|
|
let(:contact) { create(:contact, account: account, email: nil) }
|
|
|
|
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
|
|
|
let!(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
|
|
|
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
|
|
|
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
describe 'GET /api/v1/widget/conversations' do
|
|
|
|
context 'with a conversation' do
|
|
|
|
it 'returns the correct conversation params' do
|
|
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
|
|
get '/api/v1/widget/conversations',
|
|
|
|
headers: { 'X-Auth-Token' => token },
|
|
|
|
params: { website_token: web_widget.website_token },
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
json_response = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(json_response['id']).to eq(conversation.display_id)
|
|
|
|
expect(json_response['status']).to eq(conversation.status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-04 17:37:56 +00:00
|
|
|
describe 'POST /api/v1/widget/conversations/toggle_typing' do
|
|
|
|
context 'with a conversation' do
|
|
|
|
it 'dispatches the correct typing status' do
|
|
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
|
|
post '/api/v1/widget/conversations/toggle_typing',
|
|
|
|
headers: { 'X-Auth-Token' => token },
|
|
|
|
params: { typing_status: 'on', website_token: web_widget.website_token },
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
|
|
|
.with(Conversation::CONVERSATION_TYPING_ON, kind_of(Time), { conversation: conversation, user: contact })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-09 16:32:43 +00:00
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
describe 'POST /api/v1/widget/conversations/update_last_seen' do
|
2020-05-09 16:32:43 +00:00
|
|
|
context 'with a conversation' do
|
|
|
|
it 'returns the correct conversation params' do
|
|
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
2020-07-07 18:34:44 +00:00
|
|
|
expect(conversation.user_last_seen_at).to eq(nil)
|
|
|
|
|
|
|
|
post '/api/v1/widget/conversations/update_last_seen',
|
|
|
|
headers: { 'X-Auth-Token' => token },
|
|
|
|
params: { website_token: web_widget.website_token },
|
|
|
|
as: :json
|
2020-05-09 16:32:43 +00:00
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
expect(conversation.reload.user_last_seen_at).not_to eq(nil)
|
2020-05-09 16:32:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-17 05:55:13 +00:00
|
|
|
|
|
|
|
describe 'POST /api/v1/widget/conversations/transcript' do
|
|
|
|
context 'with a conversation' do
|
|
|
|
it 'sends transcript email' do
|
|
|
|
allow(ConversationReplyMailer).to receive(:conversation_transcript)
|
|
|
|
|
|
|
|
post '/api/v1/widget/conversations/transcript',
|
|
|
|
headers: { 'X-Auth-Token' => token },
|
|
|
|
params: { website_token: web_widget.website_token, email: 'test@test.com' },
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(ConversationReplyMailer).to have_received(:conversation_transcript).with(conversation, 'test@test.com')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-04 17:37:56 +00:00
|
|
|
end
|