2020-02-17 02:21:45 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Subscriptions API', type: :request do
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
describe 'GET /api/v1/accounts/{account.id}/subscriptions' do
|
2020-02-17 02:21:45 +00:00
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
|
|
|
ENV['BILLING_ENABLED'] = 'true'
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/subscriptions"
|
2020-02-17 02:21:45 +00:00
|
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
|
|
|
|
ENV['BILLING_ENABLED'] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is an authenticated user' do
|
|
|
|
let(:agent) { create(:user, account: account, role: :agent) }
|
|
|
|
|
|
|
|
it 'returns all subscriptions' do
|
|
|
|
ENV['BILLING_ENABLED'] = 'true'
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/subscriptions",
|
2020-02-17 02:21:45 +00:00
|
|
|
headers: agent.create_new_auth_token,
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(JSON.parse(response.body)).to eq(account.subscription_data.as_json)
|
|
|
|
|
|
|
|
ENV['BILLING_ENABLED'] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'throws 404 error if env variable is not set' do
|
|
|
|
ENV['BILLING_ENABLED'] = nil
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/subscriptions",
|
2020-02-17 02:21:45 +00:00
|
|
|
headers: agent.create_new_auth_token,
|
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|