mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
Chore: Added tests for subscriptions_controller (#483)
Added tests for subscriptions_controller ref: #37
This commit is contained in:
46
spec/controllers/api/v1/subscriptions_controller_spec.rb
Normal file
46
spec/controllers/api/v1/subscriptions_controller_spec.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Subscriptions API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
describe 'GET /api/v1/subscriptions' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
ENV['BILLING_ENABLED'] = 'true'
|
||||
|
||||
get '/api/v1/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/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/subscriptions',
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user