Chatwoot/spec/controllers/api/v1/accounts/subscriptions_controller_spec.rb
Sojan Jose 19ab0fe108
Chore: Scope URLs with account_id (#601)
* Chore: Enable Users to create multiple accounts

Addresses: #402
- migrations to split roles and other attributes from users table
- make changes in code to accommodate this change

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
2020-03-09 23:27:10 +05:30

46 lines
1.3 KiB
Ruby

require 'rails_helper'
RSpec.describe 'Subscriptions API', type: :request do
let(:account) { create(:account) }
describe 'GET /api/v1/accounts/{account.id}/subscriptions' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
ENV['BILLING_ENABLED'] = 'true'
get "/api/v1/accounts/#{account.id}/subscriptions"
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'
get "/api/v1/accounts/#{account.id}/subscriptions",
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
get "/api/v1/accounts/#{account.id}/subscriptions",
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:not_found)
end
end
end
end