Merge branch 'develop' into chore/update-rails
# Conflicts: # Gemfile.lock # package.json # pnpm-lock.yaml
This commit is contained in:
@@ -28,6 +28,31 @@ RSpec.describe 'Agent Bot API', type: :request do
|
||||
expect(response.body).to include(agent_bot.access_token.token)
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
end
|
||||
|
||||
it 'properly differentiates between system bots and account bots' do
|
||||
global_bot = create(:agent_bot)
|
||||
get "/api/v1/accounts/#{account.id}/agent_bots",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
response_data = response.parsed_body
|
||||
# Find the global bot in the response
|
||||
global_bot_response = response_data.find { |bot| bot['id'] == global_bot.id }
|
||||
# Find the account bot in the response
|
||||
account_bot_response = response_data.find { |bot| bot['id'] == agent_bot.id }
|
||||
|
||||
# Verify system_bot attribute and outgoing_url for global bot
|
||||
expect(global_bot_response['system_bot']).to be(true)
|
||||
expect(global_bot_response).not_to include('outgoing_url')
|
||||
|
||||
# Verify account bot has system_bot attribute false and includes outgoing_url
|
||||
expect(account_bot_response['system_bot']).to be(false)
|
||||
expect(account_bot_response).to include('outgoing_url')
|
||||
|
||||
# Verify both bots have thumbnail field
|
||||
expect(global_bot_response).to include('thumbnail')
|
||||
expect(account_bot_response).to include('thumbnail')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,6 +85,10 @@ RSpec.describe 'Agent Bot API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(global_bot.name)
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
|
||||
# Test for system_bot attribute and webhook URL not being exposed
|
||||
expect(response.parsed_body['system_bot']).to be(true)
|
||||
expect(response.parsed_body).not_to include('outgoing_url')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -142,7 +171,7 @@ RSpec.describe 'Agent Bot API', type: :request do
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
end
|
||||
|
||||
it 'updates avatar' do
|
||||
it 'updates avatar and includes thumbnail in response' do
|
||||
# no avatar before upload
|
||||
expect(agent_bot.avatar.attached?).to be(false)
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||
@@ -153,6 +182,9 @@ RSpec.describe 'Agent Bot API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
agent_bot.reload
|
||||
expect(agent_bot.avatar.attached?).to be(true)
|
||||
|
||||
# Verify thumbnail is included in the response
|
||||
expect(response.parsed_body).to include('thumbnail')
|
||||
end
|
||||
|
||||
it 'updated avatar with avatar_url' do
|
||||
|
||||
@@ -3,12 +3,11 @@ require 'rails_helper'
|
||||
RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:portal) { create(:portal, name: 'test_portal', account_id: account.id) }
|
||||
let!(:category) { create(:category, name: 'category', portal: portal, account_id: account.id, locale: 'en', slug: 'category_slug') }
|
||||
let!(:article) { create(:article, category: category, portal: portal, account_id: account.id, author_id: agent.id) }
|
||||
|
||||
before { create(:portal_member, user: agent, portal: portal) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/portals/{portal.slug}/articles' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
@@ -33,7 +32,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
@@ -56,7 +55,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
@@ -84,7 +83,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
@@ -110,7 +109,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
@@ -144,7 +143,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article.id}",
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql(article_params[:article][:title])
|
||||
@@ -165,7 +164,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
it 'deletes category' do
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
deleted_article = Article.find_by(id: article.id)
|
||||
expect(deleted_article).to be_nil
|
||||
@@ -187,7 +186,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
expect(article2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
headers: agent.create_new_auth_token,
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {}
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -199,7 +198,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
expect(article2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
headers: agent.create_new_auth_token,
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {}
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -213,7 +212,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
expect(article2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
headers: agent.create_new_auth_token,
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { category_slug: category.slug }
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -230,14 +229,14 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
expect(article2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||
headers: agent.create_new_auth_token,
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { query: 'funny' }
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be 1
|
||||
expect(json_response['meta']['all_articles_count']).to be 2
|
||||
expect(json_response['meta']['articles_count']).to be 1
|
||||
expect(json_response['meta']['mine_articles_count']).to be 1
|
||||
expect(json_response['meta']['mine_articles_count']).to be 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -247,7 +246,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
expect(article2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article2.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
|
||||
@@ -263,7 +262,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
associated_article_id: root_article.id)
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{root_article.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ 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, trigger_rules: { url: 'https://test.com' }) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
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}/campaigns",
|
||||
@@ -128,7 +129,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
|
||||
it 'creates a new oneoff campaign' do
|
||||
twilio_sms = create(:channel_twilio_sms, account: account)
|
||||
twilio_inbox = create(:inbox, channel: twilio_sms)
|
||||
twilio_inbox = create(:inbox, channel: twilio_sms, account: account)
|
||||
label1 = create(:label, account: account)
|
||||
label2 = create(:label, account: account)
|
||||
scheduled_at = 2.days.from_now
|
||||
|
||||
@@ -3,6 +3,7 @@ require 'rails_helper'
|
||||
RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:portal) { create(:portal, name: 'test_portal', account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
let!(:category) { create(:category, name: 'category', portal: portal, account_id: account.id, slug: 'category_slug', position: 1) }
|
||||
let!(:category_to_associate) do
|
||||
@@ -15,8 +16,6 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
create(:category, name: 'related category 2', portal: portal, account_id: account.id, slug: 'category_slug_2', position: 4)
|
||||
end
|
||||
|
||||
before { create(:portal_member, user: agent, portal: portal) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/portals/{portal.slug}/categories' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
@@ -59,7 +58,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
it 'creates category' do
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = response.parsed_body
|
||||
@@ -75,11 +74,11 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
it 'creates multiple sub_categories under one parent_category' do
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params_2,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(category.reload.sub_category_ids).to eql(Category.last(2).pluck(:id))
|
||||
@@ -88,11 +87,11 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
it 'creates multiple associated_categories with one category' do
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params_2,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(category_to_associate.reload.associated_category_ids).to eql(Category.last(2).pluck(:id))
|
||||
@@ -101,11 +100,11 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
it 'will throw an error on locale, category_id uniqueness' do
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eql('Locale should be unique in the category and portal')
|
||||
@@ -123,7 +122,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = response.parsed_body
|
||||
|
||||
@@ -158,7 +157,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
json_response = response.parsed_body
|
||||
|
||||
@@ -181,7 +180,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
@@ -209,7 +208,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{related_category_2.id}",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
@@ -230,7 +229,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
it 'deletes category' do
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
deleted_category = Category.find_by(id: category.id)
|
||||
expect(deleted_category).to be_nil
|
||||
@@ -255,7 +254,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
expect(category2.id).not_to be_nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be(category_count + 1)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Instagram Authorization API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/instagram/authorization' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/instagram/authorization"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:administrator) { create(:user, account: account, role: :administrator) }
|
||||
|
||||
it 'returns unauthorized for agent' do
|
||||
post "/api/v1/accounts/#{account.id}/instagram/authorization",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it 'creates a new authorization and returns the redirect url' do
|
||||
post "/api/v1/accounts/#{account.id}/instagram/authorization",
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.parsed_body['success']).to be true
|
||||
|
||||
instagram_service = Class.new do
|
||||
extend InstagramConcern
|
||||
extend Instagram::IntegrationHelper
|
||||
end
|
||||
frontend_url = ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
|
||||
response_url = instagram_service.instagram_client.auth_code.authorize_url(
|
||||
{
|
||||
redirect_uri: "#{frontend_url}/instagram/callback",
|
||||
scope: Instagram::IntegrationHelper::REQUIRED_SCOPES.join(','),
|
||||
enable_fb_login: '0',
|
||||
force_authentication: '1',
|
||||
response_type: 'code',
|
||||
state: instagram_service.generate_instagram_token(account.id)
|
||||
}
|
||||
)
|
||||
expect(response.parsed_body['url']).to eq response_url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,187 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Stub class for ShopifyAPI response
|
||||
class ShopifyAPIResponse
|
||||
attr_reader :body
|
||||
|
||||
def initialize(body)
|
||||
@body = body
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe 'Shopify Integration API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:unauthorized_agent) { create(:user, account: account, role: :agent) }
|
||||
let(:contact) { create(:contact, account: account, email: 'test@example.com', phone_number: '+1234567890') }
|
||||
|
||||
describe 'POST /api/v1/accounts/:account_id/integrations/shopify/auth' do
|
||||
let(:shop_domain) { 'test-store.myshopify.com' }
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'returns a redirect URL for Shopify OAuth' do
|
||||
post "/api/v1/accounts/#{account.id}/integrations/shopify/auth",
|
||||
params: { shop_domain: shop_domain },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body).to have_key('redirect_url')
|
||||
expect(response.parsed_body['redirect_url']).to include(shop_domain)
|
||||
end
|
||||
|
||||
it 'returns error when shop domain is missing' do
|
||||
post "/api/v1/accounts/#{account.id}/integrations/shopify/auth",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.parsed_body['error']).to eq('Shop domain is required')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/integrations/shopify/auth",
|
||||
params: { shop_domain: shop_domain },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/:account_id/integrations/shopify/orders' do
|
||||
before do
|
||||
create(:integrations_hook, :shopify, account: account)
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
# rubocop:disable RSpec/AnyInstance
|
||||
let(:shopify_client) { instance_double(ShopifyAPI::Clients::Rest::Admin) }
|
||||
|
||||
let(:customers_response) do
|
||||
instance_double(
|
||||
ShopifyAPIResponse,
|
||||
body: { 'customers' => [{ 'id' => '123' }] }
|
||||
)
|
||||
end
|
||||
|
||||
let(:orders_response) do
|
||||
instance_double(
|
||||
ShopifyAPIResponse,
|
||||
body: {
|
||||
'orders' => [{
|
||||
'id' => '456',
|
||||
'email' => 'test@example.com',
|
||||
'created_at' => Time.now.iso8601,
|
||||
'total_price' => '100.00',
|
||||
'currency' => 'USD',
|
||||
'fulfillment_status' => 'fulfilled',
|
||||
'financial_status' => 'paid'
|
||||
}]
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Api::V1::Accounts::Integrations::ShopifyController).to receive(:shopify_client).and_return(shopify_client)
|
||||
|
||||
allow_any_instance_of(Api::V1::Accounts::Integrations::ShopifyController).to receive(:client_id).and_return('test_client_id')
|
||||
allow_any_instance_of(Api::V1::Accounts::Integrations::ShopifyController).to receive(:client_secret).and_return('test_client_secret')
|
||||
|
||||
allow(shopify_client).to receive(:get).with(
|
||||
path: 'customers/search.json',
|
||||
query: { query: "email:#{contact.email} OR phone:#{contact.phone_number}", fields: 'id,email,phone' }
|
||||
).and_return(customers_response)
|
||||
|
||||
allow(shopify_client).to receive(:get).with(
|
||||
path: 'orders.json',
|
||||
query: { customer_id: '123', status: 'any', fields: 'id,email,created_at,total_price,currency,fulfillment_status,financial_status' }
|
||||
).and_return(orders_response)
|
||||
end
|
||||
|
||||
it 'returns orders for the contact' do
|
||||
get "/api/v1/accounts/#{account.id}/integrations/shopify/orders",
|
||||
params: { contact_id: contact.id },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body).to have_key('orders')
|
||||
expect(response.parsed_body['orders'].length).to eq(1)
|
||||
expect(response.parsed_body['orders'][0]['id']).to eq('456')
|
||||
end
|
||||
|
||||
it 'returns error when contact has no email or phone' do
|
||||
contact_without_info = create(:contact, account: account)
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/integrations/shopify/orders",
|
||||
params: { contact_id: contact_without_info.id },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.parsed_body['error']).to eq('Contact information missing')
|
||||
end
|
||||
|
||||
it 'returns empty array when no customers found' do
|
||||
empty_customers_response = instance_double(
|
||||
ShopifyAPIResponse,
|
||||
body: { 'customers' => [] }
|
||||
)
|
||||
|
||||
allow(shopify_client).to receive(:get).with(
|
||||
path: 'customers/search.json',
|
||||
query: { query: "email:#{contact.email} OR phone:#{contact.phone_number}", fields: 'id,email,phone' }
|
||||
).and_return(empty_customers_response)
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/integrations/shopify/orders",
|
||||
params: { contact_id: contact.id },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body['orders']).to eq([])
|
||||
end
|
||||
# rubocop:enable RSpec/AnyInstance
|
||||
end
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get "/api/v1/accounts/#{account.id}/integrations/shopify/orders",
|
||||
params: { contact_id: contact.id },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /api/v1/accounts/:account_id/integrations/shopify' do
|
||||
before do
|
||||
create(:integrations_hook, :shopify, account: account)
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'deletes the shopify integration' do
|
||||
expect do
|
||||
delete "/api/v1/accounts/#{account.id}/integrations/shopify",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
end.to change { account.hooks.count }.by(-1)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
delete "/api/v1/accounts/#{account.id}/integrations/shopify",
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,8 +8,6 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
let(:agent_2) { create(:user, account: account, role: :agent) }
|
||||
let!(:portal) { create(:portal, slug: 'portal-1', name: 'test_portal', account_id: account.id) }
|
||||
|
||||
before { create(:portal_member, user: agent, portal: portal) }
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/portals' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
@@ -23,7 +21,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
portal2 = create(:portal, name: 'test_portal_2', account_id: account.id, slug: 'portal-2')
|
||||
expect(portal2.id).not_to be_nil
|
||||
get "/api/v1/accounts/#{account.id}/portals",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -45,7 +43,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
it 'get one portals' do
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -62,7 +60,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
create(:article, category_id: es_cat.id, portal_id: portal.id, author_id: agent.id)
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}?locale=en",
|
||||
headers: agent.create_new_auth_token
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
@@ -178,38 +176,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT /api/v1/accounts/{account.id}/portals/{portal.slug}/add_members' do
|
||||
let(:new_account) { create(:account) }
|
||||
let(:new_agent) { create(:user, account: new_account, role: :agent) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/add_members", params: {}
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'add members to the portal' do
|
||||
portal_params = {
|
||||
portal: {
|
||||
member_ids: [agent_1.id, agent_2.id]
|
||||
}
|
||||
}
|
||||
expect(portal.members.count).to be(1)
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/add_members",
|
||||
params: portal_params,
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(portal.reload.member_ids).to include(agent_1.id)
|
||||
expect(json_response['portal_members'].length).to be(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
# Portal members endpoint removed
|
||||
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/portals/{portal.slug}/logo' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
|
||||
Reference in New Issue
Block a user