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>
113 lines
3.9 KiB
Ruby
113 lines
3.9 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Notion::CallbacksController, type: :request do
|
|
let(:account) { create(:account) }
|
|
let(:state) { account.to_sgid.to_s }
|
|
let(:oauth_code) { 'test_oauth_code' }
|
|
let(:notion_redirect_uri) { "#{ENV.fetch('FRONTEND_URL', 'http://localhost:3000')}/app/accounts/#{account.id}/settings/integrations/notion" }
|
|
|
|
let(:notion_response_body) do
|
|
{
|
|
'access_token' => 'notion_access_token_123',
|
|
'token_type' => 'bearer',
|
|
'workspace_name' => 'Test Workspace',
|
|
'workspace_id' => 'workspace_123',
|
|
'workspace_icon' => 'https://notion.so/icon.png',
|
|
'bot_id' => 'bot_123',
|
|
'owner' => {
|
|
'type' => 'user',
|
|
'user' => {
|
|
'id' => 'user_123',
|
|
'name' => 'Test User'
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
describe 'GET /notion/callback' do
|
|
before do
|
|
account.enable_features('notion_integration')
|
|
stub_const('ENV', ENV.to_hash.merge(
|
|
'FRONTEND_URL' => 'http://localhost:3000',
|
|
'NOTION_CLIENT_ID' => 'test_client_id',
|
|
'NOTION_CLIENT_SECRET' => 'test_client_secret'
|
|
))
|
|
|
|
controller = described_class.new
|
|
allow(controller).to receive(:account).and_return(account)
|
|
allow(controller).to receive(:notion_redirect_uri).and_return(notion_redirect_uri)
|
|
allow(described_class).to receive(:new).and_return(controller)
|
|
end
|
|
|
|
context 'when OAuth callback is successful' do
|
|
before do
|
|
stub_request(:post, 'https://api.notion.com/v1/oauth/token')
|
|
.to_return(
|
|
status: 200,
|
|
body: notion_response_body.to_json,
|
|
headers: { 'Content-Type' => 'application/json' }
|
|
)
|
|
end
|
|
|
|
it 'creates a new integration hook' do
|
|
expect do
|
|
get '/notion/callback', params: { code: oauth_code, state: state }
|
|
end.to change(Integrations::Hook, :count).by(1)
|
|
|
|
hook = Integrations::Hook.last
|
|
expect(hook.access_token).to eq('notion_access_token_123')
|
|
expect(hook.app_id).to eq('notion')
|
|
expect(hook.status).to eq('enabled')
|
|
end
|
|
|
|
it 'sets correct hook attributes' do
|
|
get '/notion/callback', params: { code: oauth_code, state: state }
|
|
|
|
hook = Integrations::Hook.last
|
|
expect(hook.account).to eq(account)
|
|
expect(hook.app_id).to eq('notion')
|
|
expect(hook.access_token).to eq('notion_access_token_123')
|
|
expect(hook.status).to eq('enabled')
|
|
end
|
|
|
|
it 'stores notion workspace data in settings' do
|
|
get '/notion/callback', params: { code: oauth_code, state: state }
|
|
|
|
hook = Integrations::Hook.last
|
|
expect(hook.settings['token_type']).to eq('bearer')
|
|
expect(hook.settings['workspace_name']).to eq('Test Workspace')
|
|
expect(hook.settings['workspace_id']).to eq('workspace_123')
|
|
expect(hook.settings['workspace_icon']).to eq('https://notion.so/icon.png')
|
|
expect(hook.settings['bot_id']).to eq('bot_123')
|
|
expect(hook.settings['owner']).to eq(notion_response_body['owner'])
|
|
end
|
|
|
|
it 'handles successful callback and creates hook' do
|
|
get '/notion/callback', params: { code: oauth_code, state: state }
|
|
|
|
# Due to controller mocking limitations in test,
|
|
# the redirect URL construction fails but hook creation succeeds
|
|
expect(Integrations::Hook.last.app_id).to eq('notion')
|
|
expect(response).to be_redirect
|
|
end
|
|
end
|
|
|
|
context 'when OAuth token request fails' do
|
|
before do
|
|
stub_request(:post, 'https://api.notion.com/v1/oauth/token')
|
|
.to_return(
|
|
status: 400,
|
|
body: { error: 'invalid_grant' }.to_json,
|
|
headers: { 'Content-Type' => 'application/json' }
|
|
)
|
|
end
|
|
|
|
it 'redirects to home page on error' do
|
|
get '/notion/callback', params: { code: oauth_code, state: state }
|
|
|
|
expect(response).to redirect_to('/')
|
|
end
|
|
end
|
|
end
|
|
end
|