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>
89 lines
2.9 KiB
Ruby
89 lines
2.9 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Linear::CallbacksController, type: :request do
|
|
let(:account) { create(:account) }
|
|
let(:code) { SecureRandom.hex(10) }
|
|
let(:client_secret) { 'test_linear_secret' }
|
|
let(:state) { JWT.encode({ sub: account.id, iat: Time.current.to_i }, client_secret, 'HS256') }
|
|
let(:linear_redirect_uri) { "#{ENV.fetch('FRONTEND_URL', '')}/app/accounts/#{account.id}/settings/integrations/linear" }
|
|
|
|
describe 'GET /linear/callback' do
|
|
let(:access_token) { SecureRandom.hex(10) }
|
|
let(:response_body) do
|
|
{
|
|
'access_token' => access_token,
|
|
'token_type' => 'Bearer',
|
|
'expires_in' => 7200,
|
|
'scope' => 'read,write'
|
|
}
|
|
end
|
|
|
|
before do
|
|
stub_const('ENV', ENV.to_hash.merge('FRONTEND_URL' => 'http://www.example.com'))
|
|
allow(GlobalConfigService).to receive(:load).and_call_original
|
|
allow(GlobalConfigService).to receive(:load).with('LINEAR_CLIENT_SECRET', nil).and_return(client_secret)
|
|
allow(GlobalConfigService).to receive(:load).with('LINEAR_CLIENT_ID', nil).and_return('test_client_id')
|
|
end
|
|
|
|
context 'when successful' do
|
|
before do
|
|
stub_request(:post, 'https://api.linear.app/oauth/token')
|
|
.to_return(
|
|
status: 200,
|
|
body: response_body.to_json,
|
|
headers: { 'Content-Type' => 'application/json' }
|
|
)
|
|
end
|
|
|
|
it 'creates a new integration hook' do
|
|
expect do
|
|
get linear_callback_path, params: { code: code, state: state }
|
|
end.to change(Integrations::Hook, :count).by(1)
|
|
|
|
hook = Integrations::Hook.last
|
|
expect(hook.access_token).to eq(access_token)
|
|
expect(hook.app_id).to eq('linear')
|
|
expect(hook.status).to eq('enabled')
|
|
expect(hook.settings).to eq(
|
|
'token_type' => 'Bearer',
|
|
'expires_in' => 7200,
|
|
'scope' => 'read,write'
|
|
)
|
|
expect(response).to redirect_to(linear_redirect_uri)
|
|
end
|
|
end
|
|
|
|
context 'when the code is missing' do
|
|
before do
|
|
stub_request(:post, 'https://api.linear.app/oauth/token')
|
|
.to_return(
|
|
status: 200,
|
|
body: response_body.to_json,
|
|
headers: { 'Content-Type' => 'application/json' }
|
|
)
|
|
end
|
|
|
|
it 'redirects to the linear_redirect_uri' do
|
|
get linear_callback_path, params: { state: state }
|
|
expect(response).to redirect_to(linear_redirect_uri)
|
|
end
|
|
end
|
|
|
|
context 'when the token is invalid' do
|
|
before do
|
|
stub_request(:post, 'https://api.linear.app/oauth/token')
|
|
.to_return(
|
|
status: 400,
|
|
body: { error: 'invalid_grant' }.to_json,
|
|
headers: { 'Content-Type' => 'application/json' }
|
|
)
|
|
end
|
|
|
|
it 'redirects to the linear_redirect_uri' do
|
|
get linear_callback_path, params: { code: code, state: state }
|
|
expect(response).to redirect_to(linear_redirect_uri)
|
|
end
|
|
end
|
|
end
|
|
end
|