2020-06-12 17:42:47 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Integration Apps API', type: :request do
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
|
|
|
|
describe 'GET /api/v1/integrations/apps' do
|
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
|
|
|
get api_v1_account_integrations_apps_url(account)
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is an authenticated user' do
|
2021-06-11 06:14:31 +00:00
|
|
|
let(:agent) { create(:user, account: account, role: :administrator) }
|
2020-06-12 17:42:47 +00:00
|
|
|
|
2020-06-25 18:05:16 +00:00
|
|
|
it 'returns all active apps' do
|
|
|
|
first_app = Integrations::App.all.find(&:active?)
|
2020-06-12 17:42:47 +00:00
|
|
|
get api_v1_account_integrations_apps_url(account),
|
|
|
|
headers: agent.create_new_auth_token,
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
2020-06-25 18:05:16 +00:00
|
|
|
apps = JSON.parse(response.body)['payload'].first
|
|
|
|
expect(apps['id']).to eql(first_app.id)
|
|
|
|
expect(apps['name']).to eql(first_app.name)
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
2021-05-20 18:33:09 +00:00
|
|
|
|
|
|
|
it 'returns slack app with appropriate redirect url when configured' do
|
2021-10-25 07:43:25 +00:00
|
|
|
with_modified_env SLACK_CLIENT_ID: 'client_id', SLACK_CLIENT_SECRET: 'client_secret' do
|
|
|
|
get api_v1_account_integrations_apps_url(account),
|
|
|
|
headers: agent.create_new_auth_token,
|
|
|
|
as: :json
|
2021-05-20 18:33:09 +00:00
|
|
|
|
2021-10-25 07:43:25 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
apps = JSON.parse(response.body)['payload']
|
|
|
|
slack_app = apps.find { |app| app['id'] == 'slack' }
|
|
|
|
expect(slack_app['action']).to include('client_id=client_id')
|
|
|
|
end
|
2021-05-20 18:33:09 +00:00
|
|
|
end
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /api/v1/integrations/apps/:id' do
|
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
2020-06-22 07:49:26 +00:00
|
|
|
get api_v1_account_integrations_app_url(account_id: account.id, id: 'slack')
|
2020-06-12 17:42:47 +00:00
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is an authenticated user' do
|
2021-06-11 06:14:31 +00:00
|
|
|
let(:agent) { create(:user, account: account, role: :administrator) }
|
2020-06-12 17:42:47 +00:00
|
|
|
|
|
|
|
it 'returns details of the app' do
|
2020-06-22 07:49:26 +00:00
|
|
|
get api_v1_account_integrations_app_url(account_id: account.id, id: 'slack'),
|
2020-06-12 17:42:47 +00:00
|
|
|
headers: agent.create_new_auth_token,
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
app = JSON.parse(response.body)
|
2020-06-22 07:49:26 +00:00
|
|
|
expect(app['id']).to eql('slack')
|
2020-06-12 17:42:47 +00:00
|
|
|
expect(app['name']).to eql('Slack')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|