Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
122 lines
4.3 KiB
Ruby
122 lines
4.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe 'API Base', type: :request do
|
|
let!(:account) { create(:account) }
|
|
let!(:user) { create(:user, account: account) }
|
|
|
|
describe 'request with api_access_token for user' do
|
|
context 'when accessing an account scoped resource' do
|
|
let!(:admin) { create(:user, :administrator, account: account) }
|
|
let!(:conversation) { create(:conversation, account: account) }
|
|
|
|
it 'sets Current attributes for the request and then returns the response' do
|
|
# This test verifies that Current.user, Current.account, and Current.account_user
|
|
# are properly set during request processing. We verify this indirectly:
|
|
# - A successful response proves Current.account_user was set (required for authorization)
|
|
# - The correct conversation data proves Current.account was set (scopes the query)
|
|
get "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}",
|
|
headers: { api_access_token: admin.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.parsed_body['id']).to eq(conversation.display_id)
|
|
end
|
|
end
|
|
|
|
context 'when it is an invalid api_access_token' do
|
|
it 'returns unauthorized' do
|
|
get '/api/v1/profile',
|
|
headers: { api_access_token: 'invalid' },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
|
|
context 'when it is a valid api_access_token' do
|
|
it 'returns current user information' do
|
|
get '/api/v1/profile',
|
|
headers: { api_access_token: user.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:success)
|
|
json_response = response.parsed_body
|
|
expect(json_response['id']).to eq(user.id)
|
|
expect(json_response['email']).to eq(user.email)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'request with api_access_token for a super admin' do
|
|
before do
|
|
user.update!(type: 'SuperAdmin')
|
|
end
|
|
|
|
context 'when its a valid api_access_token' do
|
|
it 'returns current user information' do
|
|
get '/api/v1/profile',
|
|
headers: { api_access_token: user.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:success)
|
|
json_response = response.parsed_body
|
|
expect(json_response['id']).to eq(user.id)
|
|
expect(json_response['email']).to eq(user.email)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'request with api_access_token for bot' do
|
|
let!(:agent_bot) { create(:agent_bot) }
|
|
let!(:inbox) { create(:inbox, account: account) }
|
|
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user, status: 'pending') }
|
|
|
|
context 'when it is an unauthorized url' do
|
|
it 'returns unauthorized' do
|
|
get '/api/v1/profile',
|
|
headers: { api_access_token: agent_bot.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
|
|
context 'when it is a accessible url' do
|
|
it 'returns success' do
|
|
create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot)
|
|
|
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
|
|
headers: { api_access_token: agent_bot.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:success)
|
|
expect(conversation.reload.status).to eq('open')
|
|
end
|
|
end
|
|
|
|
context 'when the account is suspended' do
|
|
it 'returns 401 unauthorized' do
|
|
account.update!(status: :suspended)
|
|
|
|
post "/api/v1/accounts/#{account.id}/canned_responses",
|
|
headers: { api_access_token: user.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
|
|
# this exception occured in a client instance (DoubleRender error)
|
|
it 'will not throw exception if user does not have access to suspended account' do
|
|
user_with_out_access = create(:user)
|
|
account.update!(status: :suspended)
|
|
|
|
post "/api/v1/accounts/#{account.id}/canned_responses",
|
|
headers: { api_access_token: user_with_out_access.access_token.token },
|
|
as: :json
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|
|
end
|