fix: Ongoing campaign URL validation (#3890)
This commit is contained in:
@@ -15,7 +15,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:administrator) { create(:user, account: account, role: :administrator) }
|
||||
let!(:campaign) { create(:campaign, account: account) }
|
||||
let!(:campaign) { create(:campaign, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
it 'returns unauthorized for agents' do
|
||||
get "/api/v1/accounts/#{account.id}/campaigns",
|
||||
@@ -38,7 +38,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/campaigns/:id' do
|
||||
let(:campaign) { create(:campaign, account: account) }
|
||||
let(:campaign) { create(:campaign, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
@@ -107,6 +107,25 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
expect(JSON.parse(response.body, symbolize_names: true)[:title]).to eq('test')
|
||||
end
|
||||
|
||||
it 'creates a new ongoing campaign' do
|
||||
post "/api/v1/accounts/#{account.id}/campaigns",
|
||||
params: { inbox_id: inbox.id, title: 'test', message: 'test message', trigger_rules: { url: 'https://test.com' } },
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body, symbolize_names: true)[:title]).to eq('test')
|
||||
end
|
||||
|
||||
it 'throws error when invalid url provided for ongoing campaign' do
|
||||
post "/api/v1/accounts/#{account.id}/campaigns",
|
||||
params: { inbox_id: inbox.id, title: 'test', message: 'test message', trigger_rules: { url: 'javascript' } },
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it 'creates a new oneoff campaign' do
|
||||
twilio_sms = create(:channel_twilio_sms, account: account)
|
||||
twilio_inbox = create(:inbox, channel: twilio_sms)
|
||||
@@ -133,7 +152,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
|
||||
describe 'PATCH /api/v1/accounts/{account.id}/campaigns/:id' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let!(:campaign) { create(:campaign, account: account) }
|
||||
let!(:campaign) { create(:campaign, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
@@ -172,7 +191,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/campaigns/:id' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let!(:campaign) { create(:campaign, account: account) }
|
||||
let!(:campaign) { create(:campaign, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
|
||||
@@ -133,7 +133,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:administrator) { create(:user, account: account, role: :administrator) }
|
||||
|
||||
let!(:campaign) { create(:campaign, account: account, inbox: inbox) }
|
||||
let!(:campaign) { create(:campaign, account: account, inbox: inbox, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
it 'returns unauthorized for agents' do
|
||||
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
|
||||
@@ -145,7 +145,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
|
||||
it 'returns all campaigns belonging to the inbox to administrators' do
|
||||
# create a random campaign
|
||||
create(:campaign, account: account)
|
||||
create(:campaign, account: account, trigger_rules: { url: 'https://test.com' })
|
||||
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
@@ -3,8 +3,8 @@ require 'rails_helper'
|
||||
RSpec.describe '/api/v1/widget/campaigns', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:web_widget) { create(:channel_widget, account: account) }
|
||||
let!(:campaign_1) { create(:campaign, inbox: web_widget.inbox, enabled: true, account: account) }
|
||||
let!(:campaign_2) { create(:campaign, inbox: web_widget.inbox, enabled: false, account: account) }
|
||||
let!(:campaign_1) { create(:campaign, inbox: web_widget.inbox, enabled: true, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
let!(:campaign_2) { create(:campaign, inbox: web_widget.inbox, enabled: false, account: account, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
describe 'GET /api/v1/widget/campaigns' do
|
||||
let(:params) { { website_token: web_widget.website_token } }
|
||||
|
||||
Reference in New Issue
Block a user