mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-31 19:17:48 +00:00
Users get confused between app routes and API routes. Instead of hitting /api, they append /app in the API call, which ends up calling the dashboard controller and throws an error. To fix this, we added a check to throw a 406 Not Acceptable for non-HTML requests. But Meta requires Accept: \*/\* to return 200 for the integration to be accepted. This change will only throw an error for JSON requests. Fixes #11697 Fixes https://github.com/chatwoot/chatwoot/issues/11251 Fixes https://github.com/chatwoot/chatwoot/issues/11205
43 lines
1.3 KiB
Ruby
43 lines
1.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe '/app/login', type: :request do
|
|
context 'without DEFAULT_LOCALE' do
|
|
it 'renders the dashboard' do
|
|
get '/app/login'
|
|
expect(response).to have_http_status(:success)
|
|
end
|
|
end
|
|
|
|
context 'with DEFAULT_LOCALE' do
|
|
it 'renders the dashboard' do
|
|
with_modified_env DEFAULT_LOCALE: 'pt_BR' do
|
|
get '/app/login'
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.body).to include "selectedLocale: 'pt_BR'"
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with non-HTML format' do
|
|
it 'returns not acceptable for JSON with error message' do
|
|
get '/app/login', headers: { 'Accept' => 'application/json' }
|
|
expect(response).to have_http_status(:not_acceptable)
|
|
expect(response.parsed_body).to eq({ 'error' => 'Please use API routes instead of dashboard routes for JSON requests' })
|
|
end
|
|
end
|
|
|
|
# Routes are loaded once on app start
|
|
# hence Rails.application.reload_routes! is used in this spec
|
|
# ref : https://stackoverflow.com/a/63584877/939299
|
|
context 'with CW_API_ONLY_SERVER true' do
|
|
it 'returns 404' do
|
|
with_modified_env CW_API_ONLY_SERVER: 'true' do
|
|
Rails.application.reload_routes!
|
|
get '/app/login'
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
Rails.application.reload_routes!
|
|
end
|
|
end
|
|
end
|