2020-01-09 07:36:40 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe '/widget', type: :request do
|
2020-02-07 07:44:07 +00:00
|
|
|
let(:account) { create(:account) }
|
2020-01-09 07:36:40 +00:00
|
|
|
let(:web_widget) { create(:channel_widget) }
|
2020-02-07 07:44:07 +00:00
|
|
|
let(:contact) { create(:contact, account: account) }
|
|
|
|
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.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-01-09 07:36:40 +00:00
|
|
|
|
|
|
|
describe 'GET /widget' do
|
|
|
|
it 'renders the page correctly when called with website_token' do
|
|
|
|
get widget_url(website_token: web_widget.website_token)
|
|
|
|
expect(response).to be_successful
|
2020-02-07 07:44:07 +00:00
|
|
|
expect(response.body).not_to include(token)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the page correctly when called with website_token and cw_conversation' do
|
|
|
|
get widget_url(website_token: web_widget.website_token, cw_conversation: token)
|
|
|
|
expect(response).to be_successful
|
|
|
|
expect(response.body).to include(token)
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 when called with out website_token' do
|
|
|
|
get widget_url
|
2022-07-15 02:51:59 +00:00
|
|
|
expect(response).to have_http_status(:not_found)
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|