Chore: Web widget Inbox Tech Debts (#738)
* Chore: Webwidget Inbox Tech Debts * Additional customization options creating Web Widget * Changes to edit Page for Web Widget * Remove the WebWidget API end points * Minor chores Address: #680, #502 Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Callbacks API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:valid_params) { attributes_for(:channel_facebook_page).merge(page_name: 'Test', inbox_name: 'Test Inbox') }
|
||||
let(:valid_params) { attributes_for(:channel_facebook_page).merge(inbox_name: 'Test Inbox') }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let!(:facebook_page) { create(:channel_facebook_page, inbox: inbox, account: account) }
|
||||
|
||||
|
||||
@@ -88,6 +88,44 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/inboxes' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) { { name: 'test', channel: { type: 'web_widget', website_url: 'test.com' } } }
|
||||
|
||||
it 'creates inbox' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include('test.com')
|
||||
end
|
||||
|
||||
it 'will not create inbox for agent' do
|
||||
agent = create(:user, account: account, role: :agent)
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/inboxes",
|
||||
headers: agent.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /api/v1/accounts/{account.id}/inboxes/:id' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
@@ -101,7 +139,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) { { inbox: { enable_auto_assignment: false } } }
|
||||
let(:valid_params) { { enable_auto_assignment: false, channel: { website_url: 'test.com' } } }
|
||||
|
||||
it 'updates inbox' do
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||
@@ -118,10 +156,11 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(inbox.avatar.attached?).to eq(false)
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||
params: { inbox: { avatar: file } },
|
||||
params: valid_params.merge(avatar: file),
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include('test.com')
|
||||
inbox.reload
|
||||
expect(inbox.avatar.attached?).to eq(true)
|
||||
end
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe '/api/v1/accounts/{account.id}/widget/inboxes', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/widget/inboxes' do
|
||||
let(:params) { { website: { website_name: 'test', website_url: 'test.com', widget_color: '#eaeaea' } } }
|
||||
|
||||
context 'when unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/widget/inboxes", params: params
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is logged in' do
|
||||
context 'with user as administrator' do
|
||||
it 'creates inbox and returns website_token' do
|
||||
post "/api/v1/accounts/#{account.id}/widget/inboxes", params: params, headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
|
||||
expect(json_response['name']).to eq('test')
|
||||
expect(json_response['website_token']).not_to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with user as agent' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/widget/inboxes",
|
||||
params: params,
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /api/v1/accounts/{account.id}/widget/inboxes/:id' do
|
||||
let(:update_params) { { website: { widget_color: '#eaeaea' } } }
|
||||
|
||||
context 'when unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
patch "/api/v1/accounts/#{account.id}/widget/inboxes/#{inbox.channel_id}", params: update_params
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is logged in' do
|
||||
context 'with user as administrator' do
|
||||
it 'updates website channel' do
|
||||
patch "/api/v1/accounts/#{account.id}/widget/inboxes/#{inbox.channel_id}",
|
||||
params: update_params,
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
|
||||
expect(json_response['widget_color']).to eq('#eaeaea')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with user as agent' do
|
||||
it 'returns unauthorized' do
|
||||
patch "/api/v1/accounts/#{account.id}/widget/inboxes/#{inbox.channel_id}",
|
||||
params: update_params,
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
FactoryBot.define do
|
||||
factory :channel_widget, class: 'Channel::WebWidget' do
|
||||
sequence(:website_name) { |n| "Example Website #{n}" }
|
||||
sequence(:website_url) { |n| "https://example-#{n}.com" }
|
||||
sequence(:widget_color, &:to_s)
|
||||
account
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
FactoryBot.define do
|
||||
factory :channel_facebook_page, class: 'Channel::FacebookPage' do
|
||||
name { Faker::Name.name }
|
||||
page_access_token { SecureRandom.uuid }
|
||||
user_access_token { SecureRandom.uuid }
|
||||
page_id { SecureRandom.uuid }
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
FactoryBot.define do
|
||||
factory :channel_twitter_profile, class: 'Channel::TwitterProfile' do
|
||||
name { Faker::Name.name }
|
||||
twitter_access_token { SecureRandom.uuid }
|
||||
twitter_access_token_secret { SecureRandom.uuid }
|
||||
profile_id { SecureRandom.uuid }
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :facebook_page, class: 'Channel::FacebookPage' do
|
||||
sequence(:page_id) { |n| n }
|
||||
sequence(:user_access_token) { |n| "random-token-#{n}" }
|
||||
sequence(:name) { |n| "Facebook Page #{n}" }
|
||||
sequence(:page_access_token) { |n| "page-access-token-#{n}" }
|
||||
account
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@ describe Facebook::SendReplyService do
|
||||
let!(:account) { create(:account) }
|
||||
let(:bot) { class_double('Bot').as_stubbed_const }
|
||||
let!(:widget_inbox) { create(:inbox, account: account) }
|
||||
let!(:facebook_channel) { create(:facebook_page, account: account) }
|
||||
let!(:facebook_channel) { create(:channel_facebook_page, account: account) }
|
||||
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account) }
|
||||
let!(:contact) { create(:contact, account: account) }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: facebook_inbox) }
|
||||
|
||||
Reference in New Issue
Block a user