From 40f580270f6d342625b0f7a74531d300295af389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Wed, 14 Sep 2022 16:43:28 +0200 Subject: [PATCH] misc: Method json for parsed response body in specs --- spec/requests/api/v1/add_ons_spec.rb | 77 +++++++---------- spec/requests/api/v1/applied_add_ons_spec.rb | 20 ++--- spec/requests/api/v1/applied_coupons_spec.rb | 24 +++--- spec/requests/api/v1/billable_metrics_spec.rb | 63 +++++--------- spec/requests/api/v1/coupons_spec.rb | 63 +++++--------- spec/requests/api/v1/customers_spec.rb | 66 ++++++-------- spec/requests/api/v1/events_spec.rb | 12 ++- spec/requests/api/v1/invoices_spec.rb | 68 +++++---------- spec/requests/api/v1/organizations_spec.rb | 17 ++-- spec/requests/api/v1/plans_spec.rb | 83 +++++++----------- spec/requests/api/v1/subscriptions_spec.rb | 85 ++++++++----------- .../api/v1/wallet_transactions_spec.rb | 17 ++-- spec/requests/api/v1/wallets_spec.rb | 67 ++++++--------- spec/requests/api/v1/webhooks_spec.rb | 1 - spec/requests/application_spec.rb | 16 ++-- spec/requests/webhooks_spec.rb | 2 +- spec/support/api_helper.rb | 6 ++ 17 files changed, 265 insertions(+), 422 deletions(-) diff --git a/spec/requests/api/v1/add_ons_spec.rb b/spec/requests/api/v1/add_ons_spec.rb index a0a3245c2f9..d057ffd21be 100644 --- a/spec/requests/api/v1/add_ons_spec.rb +++ b/spec/requests/api/v1/add_ons_spec.rb @@ -21,11 +21,10 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:add_on] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present + expect(json[:add_on][:lago_id]).to be_present + expect(json[:add_on][:code]).to eq(create_params[:code]) + expect(json[:add_on][:name]).to eq(create_params[:name]) + expect(json[:add_on][:created_at]).to be_present end end @@ -38,22 +37,20 @@ code: code, amount_cents: 123, amount_currency: 'EUR', - description: 'description' + description: 'description', } end it 'updates a add-on' do - put_with_token(organization, - "/api/v1/add_ons/#{add_on.code}", - { add_on: update_params } + put_with_token( + organization, + "/api/v1/add_ons/#{add_on.code}", + { add_on: update_params }, ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:add_on] - - expect(result[:lago_id]).to eq(add_on.id) - expect(result[:code]).to eq(update_params[:code]) + expect(json[:add_on][:lago_id]).to eq(add_on.id) + expect(json[:add_on][:code]).to eq(update_params[:code]) end context 'when add-on does not exist' do @@ -71,9 +68,10 @@ before { add_on2 } it 'returns unprocessable_entity error' do - put_with_token(organization, - "/api/v1/add_ons/#{add_on.code}", - { add_on: update_params } + put_with_token( + organization, + "/api/v1/add_ons/#{add_on.code}", + { add_on: update_params }, ) expect(response).to have_http_status(:unprocessable_entity) @@ -87,23 +85,17 @@ it 'returns a add-on' do get_with_token( organization, - "/api/v1/add_ons/#{add_on.code}" + "/api/v1/add_ons/#{add_on.code}", ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:add_on] - - expect(result[:lago_id]).to eq(add_on.id) - expect(result[:code]).to eq(add_on.code) + expect(json[:add_on][:lago_id]).to eq(add_on.id) + expect(json[:add_on][:code]).to eq(add_on.code) end context 'when add-on does not exist' do it 'returns not found' do - get_with_token( - organization, - "/api/v1/add_ons/555" - ) + get_with_token(organization, '/api/v1/add_ons/555') expect(response).to have_http_status(:not_found) end @@ -124,11 +116,8 @@ delete_with_token(organization, "/api/v1/add_ons/#{add_on.code}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:add_on] - - expect(result[:lago_id]).to eq(add_on.id) - expect(result[:code]).to eq(add_on.code) + expect(json[:add_on][:lago_id]).to eq(add_on.id) + expect(json[:add_on][:code]).to eq(add_on.code) end context 'when add-on does not exist' do @@ -149,12 +138,9 @@ get_with_token(organization, '/api/v1/add_ons') expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:add_ons] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(add_on.id) - expect(records.first[:code]).to eq(add_on.code) + expect(json[:add_ons].count).to eq(1) + expect(json[:add_ons].first[:lago_id]).to eq(add_on.id) + expect(json[:add_ons].first[:code]).to eq(add_on.code) end context 'with pagination' do @@ -166,15 +152,12 @@ get_with_token(organization, '/api/v1/add_ons?page=1&per_page=1') expect(response).to have_http_status(:success) - - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:add_ons].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:add_ons].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end diff --git a/spec/requests/api/v1/applied_add_ons_spec.rb b/spec/requests/api/v1/applied_add_ons_spec.rb index d497522a0e8..be92137ed75 100644 --- a/spec/requests/api/v1/applied_add_ons_spec.rb +++ b/spec/requests/api/v1/applied_add_ons_spec.rb @@ -28,24 +28,20 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:applied_add_on] - aggregate_failures do - expect(result[:lago_id]).to be_present - expect(result[:lago_add_on_id]).to eq(add_on.id) - expect(result[:lago_customer_id]).to eq(customer.id) - expect(result[:external_customer_id]).to eq(customer.external_id) - expect(result[:amount_cents]).to eq(add_on.amount_cents) - expect(result[:amount_currency]).to eq(add_on.amount_currency) - expect(result[:created_at]).to be_present + expect(json[:applied_add_on][:lago_id]).to be_present + expect(json[:applied_add_on][:lago_add_on_id]).to eq(add_on.id) + expect(json[:applied_add_on][:lago_customer_id]).to eq(customer.id) + expect(json[:applied_add_on][:external_customer_id]).to eq(customer.external_id) + expect(json[:applied_add_on][:amount_cents]).to eq(add_on.amount_cents) + expect(json[:applied_add_on][:amount_currency]).to eq(add_on.amount_currency) + expect(json[:applied_add_on][:created_at]).to be_present end end context 'with invalid params' do let(:params) do - { - name: 'Foo Bar', - } + { name: 'Foo Bar' } end it 'returns an unprocessable_entity' do diff --git a/spec/requests/api/v1/applied_coupons_spec.rb b/spec/requests/api/v1/applied_coupons_spec.rb index 810a390232f..d6d3f734e4f 100644 --- a/spec/requests/api/v1/applied_coupons_spec.rb +++ b/spec/requests/api/v1/applied_coupons_spec.rb @@ -28,26 +28,22 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:applied_coupon] - aggregate_failures do - expect(result[:lago_id]).to be_present - expect(result[:lago_coupon_id]).to eq(coupon.id) - expect(result[:lago_customer_id]).to eq(customer.id) - expect(result[:external_customer_id]).to eq(customer.external_id) - expect(result[:amount_cents]).to eq(coupon.amount_cents) - expect(result[:amount_currency]).to eq(coupon.amount_currency) - expect(result[:expiration_date]).to be_nil - expect(result[:created_at]).to be_present - expect(result[:terminated_at]).to be_nil + expect(json[:applied_coupon][:lago_id]).to be_present + expect(json[:applied_coupon][:lago_coupon_id]).to eq(coupon.id) + expect(json[:applied_coupon][:lago_customer_id]).to eq(customer.id) + expect(json[:applied_coupon][:external_customer_id]).to eq(customer.external_id) + expect(json[:applied_coupon][:amount_cents]).to eq(coupon.amount_cents) + expect(json[:applied_coupon][:amount_currency]).to eq(coupon.amount_currency) + expect(json[:applied_coupon][:expiration_date]).to be_nil + expect(json[:applied_coupon][:created_at]).to be_present + expect(json[:applied_coupon][:terminated_at]).to be_nil end end context 'with invalid params' do let(:params) do - { - name: 'Foo Bar', - } + { name: 'Foo Bar' } end it 'returns an unprocessable_entity' do diff --git a/spec/requests/api/v1/billable_metrics_spec.rb b/spec/requests/api/v1/billable_metrics_spec.rb index 7d011538a9a..e29eedcfca5 100644 --- a/spec/requests/api/v1/billable_metrics_spec.rb +++ b/spec/requests/api/v1/billable_metrics_spec.rb @@ -20,12 +20,10 @@ post_with_token(organization, '/api/v1/billable_metrics', { billable_metric: create_params }) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:billable_metric] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present + expect(json[:billable_metric][:lago_id]).to be_present + expect(json[:billable_metric][:code]).to eq(create_params[:code]) + expect(json[:billable_metric][:name]).to eq(create_params[:name]) + expect(json[:billable_metric][:created_at]).to be_present end end @@ -50,11 +48,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:billable_metric] - - expect(result[:lago_id]).to eq(billable_metric.id) - expect(result[:code]).to eq(update_params[:code]) + expect(json[:billable_metric][:lago_id]).to eq(billable_metric.id) + expect(json[:billable_metric][:code]).to eq(update_params[:code]) end context 'when billable metric does not exist' do @@ -93,11 +88,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:billable_metric] - - expect(result[:lago_id]).to eq(billable_metric.id) - expect(result[:code]).to eq(billable_metric.code) + expect(json[:billable_metric][:lago_id]).to eq(billable_metric.id) + expect(json[:billable_metric][:code]).to eq(billable_metric.code) end context 'when billable metric does not exist' do @@ -126,11 +118,8 @@ delete_with_token(organization, "/api/v1/billable_metrics/#{billable_metric.code}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:billable_metric] - - expect(result[:lago_id]).to eq(billable_metric.id) - expect(result[:code]).to eq(billable_metric.code) + expect(json[:billable_metric][:lago_id]).to eq(billable_metric.id) + expect(json[:billable_metric][:code]).to eq(billable_metric.code) end context 'when billable metric does not exist' do @@ -156,11 +145,9 @@ aggregate_failures do expect(response).to have_http_status(:method_not_allowed) - - result = JSON.parse(response.body, symbolize_names: true) - expect(result[:status]).to eq(405) - expect(result[:error]).to eq('Method Not Allowed') - expect(result[:code]).to eq('attached_to_an_active_subscription') + expect(json[:status]).to eq(405) + expect(json[:error]).to eq('Method Not Allowed') + expect(json[:code]).to eq('attached_to_an_active_subscription') end end end @@ -175,12 +162,9 @@ get_with_token(organization, '/api/v1/billable_metrics') expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:billable_metrics] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(billable_metric.id) - expect(records.first[:code]).to eq(billable_metric.code) + expect(json[:billable_metrics].count).to eq(1) + expect(json[:billable_metrics].first[:lago_id]).to eq(billable_metric.id) + expect(json[:billable_metrics].first[:code]).to eq(billable_metric.code) end context 'with pagination' do @@ -192,15 +176,12 @@ get_with_token(organization, '/api/v1/billable_metrics?page=1&per_page=1') expect(response).to have_http_status(:success) - - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:billable_metrics].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:billable_metrics].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end diff --git a/spec/requests/api/v1/coupons_spec.rb b/spec/requests/api/v1/coupons_spec.rb index bf73927b356..1134416061e 100644 --- a/spec/requests/api/v1/coupons_spec.rb +++ b/spec/requests/api/v1/coupons_spec.rb @@ -21,12 +21,10 @@ post_with_token(organization, '/api/v1/coupons', { coupon: create_params }) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:coupon] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present + expect(json[:coupon][:lago_id]).to be_present + expect(json[:coupon][:code]).to eq(create_params[:code]) + expect(json[:coupon][:name]).to eq(create_params[:name]) + expect(json[:coupon][:created_at]).to be_present end end @@ -52,11 +50,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:coupon] - - expect(result[:lago_id]).to eq(coupon.id) - expect(result[:code]).to eq(update_params[:code]) + expect(json[:coupon][:lago_id]).to eq(coupon.id) + expect(json[:coupon][:code]).to eq(update_params[:code]) end context 'when coupon does not exist' do @@ -95,11 +90,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:coupon] - - expect(result[:lago_id]).to eq(coupon.id) - expect(result[:code]).to eq(coupon.code) + expect(json[:coupon][:lago_id]).to eq(coupon.id) + expect(json[:coupon][:code]).to eq(coupon.code) end context 'when coupon does not exist' do @@ -128,11 +120,8 @@ delete_with_token(organization, "/api/v1/coupons/#{coupon.code}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:coupon] - - expect(result[:lago_id]).to eq(coupon.id) - expect(result[:code]).to eq(coupon.code) + expect(json[:coupon][:lago_id]).to eq(coupon.id) + expect(json[:coupon][:code]).to eq(coupon.code) end context 'when coupon does not exist' do @@ -153,11 +142,9 @@ aggregate_failures do expect(response).to have_http_status(:method_not_allowed) - - result = JSON.parse(response.body, symbolize_names: true) - expect(result[:status]).to eq(405) - expect(result[:error]).to eq('Method Not Allowed') - expect(result[:code]).to eq('attached_to_an_active_customer') + expect(json[:status]).to eq(405) + expect(json[:error]).to eq('Method Not Allowed') + expect(json[:code]).to eq('attached_to_an_active_customer') end end end @@ -172,12 +159,9 @@ get_with_token(organization, '/api/v1/coupons') expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:coupons] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(coupon.id) - expect(records.first[:code]).to eq(coupon.code) + expect(json[:coupons].count).to eq(1) + expect(json[:coupons].first[:lago_id]).to eq(coupon.id) + expect(json[:coupons].first[:code]).to eq(coupon.code) end context 'with pagination' do @@ -189,15 +173,12 @@ get_with_token(organization, '/api/v1/coupons?page=1&per_page=1') expect(response).to have_http_status(:success) - - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:coupons].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:coupons].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 669bcf50cdd..05683da0a91 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -8,7 +8,7 @@ let(:create_params) do { external_id: SecureRandom.uuid, - name: 'Foo Bar' + name: 'Foo Bar', } end @@ -16,12 +16,10 @@ post_with_token(organization, '/api/v1/customers', { customer: create_params }) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:customer] - expect(result[:lago_id]).to be_present - expect(result[:external_id]).to eq(create_params[:external_id]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present + expect(json[:customer][:lago_id]).to be_present + expect(json[:customer][:external_id]).to eq(create_params[:external_id]) + expect(json[:customer][:name]).to eq(create_params[:name]) + expect(json[:customer][:created_at]).to be_present end context 'with billing configuration' do @@ -41,21 +39,18 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:customer] - expect(result[:lago_id]).to be_present - expect(result[:external_id]).to eq(create_params[:external_id]) + expect(json[:customer][:lago_id]).to be_present + expect(json[:customer][:external_id]).to eq(create_params[:external_id]) - expect(result[:billing_configuration]).to be_present - expect(result[:billing_configuration][:payment_provider]).to eq('stripe') - expect(result[:billing_configuration][:provider_customer_id]).to eq('stripe_id') + expect(json[:customer][:billing_configuration]).to be_present + expect(json[:customer][:billing_configuration][:payment_provider]).to eq('stripe') + expect(json[:customer][:billing_configuration][:provider_customer_id]).to eq('stripe_id') end end context 'with invalid params' do let(:create_params) do - { - name: 'Foo Bar', - } + { name: 'Foo Bar' } end it 'returns an unprocessable_entity' do @@ -121,18 +116,17 @@ aggregate_failures do expect(response).to have_http_status(:success) - usage_response = JSON.parse(response.body, symbolize_names: true)[:customer_usage] - expect(usage_response[:from_date]).to eq(Time.zone.today.beginning_of_month.iso8601) - expect(usage_response[:to_date]).to eq(Time.zone.today.end_of_month.iso8601) - expect(usage_response[:issuing_date]).to eq(Time.zone.today.end_of_month.iso8601) - expect(usage_response[:amount_cents]).to eq(5) - expect(usage_response[:amount_currency]).to eq('EUR') - expect(usage_response[:total_amount_cents]).to eq(6) - expect(usage_response[:total_amount_currency]).to eq('EUR') - expect(usage_response[:vat_amount_cents]).to eq(1) - expect(usage_response[:vat_amount_currency]).to eq('EUR') - - charge_usage = usage_response[:charges_usage].first + expect(json[:customer_usage][:from_date]).to eq(Time.zone.today.beginning_of_month.iso8601) + expect(json[:customer_usage][:to_date]).to eq(Time.zone.today.end_of_month.iso8601) + expect(json[:customer_usage][:issuing_date]).to eq(Time.zone.today.end_of_month.iso8601) + expect(json[:customer_usage][:amount_cents]).to eq(5) + expect(json[:customer_usage][:amount_currency]).to eq('EUR') + expect(json[:customer_usage][:total_amount_cents]).to eq(6) + expect(json[:customer_usage][:total_amount_currency]).to eq('EUR') + expect(json[:customer_usage][:vat_amount_cents]).to eq(1) + expect(json[:customer_usage][:vat_amount_currency]).to eq('EUR') + + charge_usage = json[:customer_usage][:charges_usage].first expect(charge_usage[:billable_metric][:name]).to eq(billable_metric.name) expect(charge_usage[:billable_metric][:code]).to eq(billable_metric.code) expect(charge_usage[:billable_metric][:aggregation_type]).to eq('count_agg') @@ -165,15 +159,11 @@ end it 'returns all customers from organization' do - get_with_token( - organization, - '/api/v1/customers', - ) + get_with_token(organization, '/api/v1/customers') - parsed_response = JSON.parse(response.body, symbolize_names: true) aggregate_failures do expect(response).to have_http_status(:ok) - expect(parsed_response[:meta][:total_count]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end @@ -192,19 +182,15 @@ "/api/v1/customers/#{customer.external_id}", ) - parsed_response = JSON.parse(response.body, symbolize_names: true) aggregate_failures do expect(response).to have_http_status(:ok) - expect(parsed_response[:customer][:lago_id]).to eq(customer.id) + expect(json[:customer][:lago_id]).to eq(customer.id) end end context 'with not existing external_id' do it 'returns a not found error' do - get_with_token( - organization, - '/api/v1/customers/foobar', - ) + get_with_token(organization, '/api/v1/customers/foobar') expect(response).to have_http_status(:not_found) end diff --git a/spec/requests/api/v1/events_spec.rb b/spec/requests/api/v1/events_spec.rb index 0402c74386f..f7457d5f6b1 100644 --- a/spec/requests/api/v1/events_spec.rb +++ b/spec/requests/api/v1/events_spec.rb @@ -94,21 +94,19 @@ expect(response).to have_http_status(:ok) - api_event = JSON.parse(response.body)['event'] - - %w[code transaction_id].each do |property| - expect(api_event[property]).to eq event.attributes[property] + %i[code transaction_id].each do |property| + expect(json[:event][property]).to eq event.attributes[property.to_s] end - expect(api_event['lago_subscription_id']).to eq event.subscription_id - expect(api_event['lago_customer_id']).to eq event.customer_id + expect(json[:event][:lago_subscription_id]).to eq event.subscription_id + expect(json[:event][:lago_customer_id]).to eq event.customer_id end context 'with a non-existing transaction_id' do it 'returns not found' do get_with_token( organization, - '/api/v1/events/' + SecureRandom.uuid + "/api/v1/events/#{SecureRandom.uuid}", ) expect(response).to have_http_status(:not_found) diff --git a/spec/requests/api/v1/invoices_spec.rb b/spec/requests/api/v1/invoices_spec.rb index 9ff895a0792..1795550083b 100644 --- a/spec/requests/api/v1/invoices_spec.rb +++ b/spec/requests/api/v1/invoices_spec.rb @@ -9,20 +9,15 @@ describe 'UPDATE /invoices' do let(:update_params) do - { - status: 'succeeded', - } + { status: 'succeeded' } end it 'updates an invoice' do put_with_token(organization, "/api/v1/invoices/#{invoice.id}", { invoice: update_params }) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:invoice] - - expect(result[:lago_id]).to eq(invoice.id) - expect(result[:status]).to eq('succeeded') + expect(json[:invoice][:lago_id]).to eq(invoice.id) + expect(json[:invoice][:status]).to eq('succeeded') end context 'when invoice does not exist' do @@ -36,25 +31,16 @@ describe 'GET /invoices/:id' do it 'returns a invoice' do - get_with_token( - organization, - "/api/v1/invoices/#{invoice.id}", - ) + get_with_token(organization, "/api/v1/invoices/#{invoice.id}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:invoice] - - expect(result[:lago_id]).to eq(invoice.id) - expect(result[:status]).to eq(invoice.status) + expect(json[:invoice][:lago_id]).to eq(invoice.id) + expect(json[:invoice][:status]).to eq(invoice.status) end context 'when invoice does not exist' do it 'returns not found' do - get_with_token( - organization, - '/api/v1/invoices/555', - ) + get_with_token(organization, '/api/v1/invoices/555') expect(response).to have_http_status(:not_found) end @@ -64,10 +50,7 @@ let(:invoice) { create(:invoice) } it 'returns not found' do - get_with_token( - organization, - "/api/v1/invoices/#{invoice.id}", - ) + get_with_token(organization, "/api/v1/invoices/#{invoice.id}") expect(response).to have_http_status(:not_found) end @@ -84,12 +67,9 @@ get_with_token(organization, '/api/v1/invoices') expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:invoices] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(invoice.id) - expect(records.first[:status]).to eq(invoice.status) + expect(json[:invoices].count).to eq(1) + expect(json[:invoices].first[:lago_id]).to eq(invoice.id) + expect(json[:invoices].first[:status]).to eq(invoice.status) end context 'with pagination' do @@ -102,14 +82,12 @@ expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:invoices].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:invoices].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end @@ -130,11 +108,8 @@ ) expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:invoices] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(invoice3.id) + expect(json[:invoices].count).to eq(1) + expect(json[:invoices].first[:lago_id]).to eq(invoice3.id) end end @@ -146,9 +121,8 @@ get_with_token(organization, "/api/v1/invoices?customer_id=#{second_customer.id}") expect(response).to have_http_status(:success) - records = JSON.parse(response.body, symbolize_names: true)[:invoices] - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(invoice.id) + expect(json[:invoices].count).to eq(1) + expect(json[:invoices].first[:lago_id]).to eq(invoice.id) end end end diff --git a/spec/requests/api/v1/organizations_spec.rb b/spec/requests/api/v1/organizations_spec.rb index 7fb411269fd..6632691b606 100644 --- a/spec/requests/api/v1/organizations_spec.rb +++ b/spec/requests/api/v1/organizations_spec.rb @@ -24,19 +24,18 @@ end it 'updates an organization' do - put_with_token(organization, - '/api/v1/organizations', - { organization: update_params } + put_with_token( + organization, + '/api/v1/organizations', + { organization: update_params }, ) expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:organization] - - expect(result[:name]).to eq(organization.name) - expect(result[:webhook_url]).to eq(update_params[:webhook_url]) - expect(result[:vat_rate]).to eq(update_params[:vat_rate]) - expect(result[:invoice_footer]).to eq(update_params[:invoice_footer]) + expect(json[:organization][:name]).to eq(organization.name) + expect(json[:organization][:webhook_url]).to eq(update_params[:webhook_url]) + expect(json[:organization][:vat_rate]).to eq(update_params[:vat_rate]) + expect(json[:organization][:invoice_footer]).to eq(update_params[:invoice_footer]) end end end diff --git a/spec/requests/api/v1/plans_spec.rb b/spec/requests/api/v1/plans_spec.rb index b321cc78074..b8057806689 100644 --- a/spec/requests/api/v1/plans_spec.rb +++ b/spec/requests/api/v1/plans_spec.rb @@ -34,12 +34,11 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:plan] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present - expect(result[:charges].first[:lago_id]).to be_present + expect(json[:plan][:lago_id]).to be_present + expect(json[:plan][:code]).to eq(create_params[:code]) + expect(json[:plan][:name]).to eq(create_params[:name]) + expect(json[:plan][:created_at]).to be_present + expect(json[:plan][:charges].first[:lago_id]).to be_present end context 'with graduated charges' do @@ -81,12 +80,11 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:plan] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present - expect(result[:charges].first[:lago_id]).to be_present + expect(json[:plan][:lago_id]).to be_present + expect(json[:plan][:code]).to eq(create_params[:code]) + expect(json[:plan][:name]).to eq(create_params[:name]) + expect(json[:plan][:created_at]).to be_present + expect(json[:plan][:charges].first[:lago_id]).to be_present end end @@ -109,12 +107,11 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:plan] - expect(result[:lago_id]).to be_present - expect(result[:code]).to eq(create_params[:code]) - expect(result[:name]).to eq(create_params[:name]) - expect(result[:created_at]).to be_present - expect(result[:charges].count).to eq(0) + expect(json[:plan][:lago_id]).to be_present + expect(json[:plan][:code]).to eq(create_params[:code]) + expect(json[:plan][:name]).to eq(create_params[:name]) + expect(json[:plan][:created_at]).to be_present + expect(json[:plan][:charges].count).to eq(0) end end end @@ -152,11 +149,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:plan] - - expect(result[:lago_id]).to eq(plan.id) - expect(result[:code]).to eq(update_params[:code]) + expect(json[:plan][:lago_id]).to eq(plan.id) + expect(json[:plan][:code]).to eq(update_params[:code]) end context 'when plan does not exist' do @@ -195,11 +189,8 @@ ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:plan] - - expect(result[:lago_id]).to eq(plan.id) - expect(result[:code]).to eq(plan.code) + expect(json[:plan][:lago_id]).to eq(plan.id) + expect(json[:plan][:code]).to eq(plan.code) end context 'when plan does not exist' do @@ -228,11 +219,8 @@ delete_with_token(organization, "/api/v1/plans/#{plan.code}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:plan] - - expect(result[:lago_id]).to eq(plan.id) - expect(result[:code]).to eq(plan.code) + expect(json[:plan][:lago_id]).to eq(plan.id) + expect(json[:plan][:code]).to eq(plan.code) end context 'when plan does not exist' do @@ -255,10 +243,9 @@ aggregate_failures do expect(response).to have_http_status(:method_not_allowed) - result = JSON.parse(response.body, symbolize_names: true) - expect(result[:status]).to eq(405) - expect(result[:error]).to eq('Method Not Allowed') - expect(result[:code]).to eq('attached_to_an_active_subscription') + expect(json[:status]).to eq(405) + expect(json[:error]).to eq('Method Not Allowed') + expect(json[:code]).to eq('attached_to_an_active_subscription') end end end @@ -274,11 +261,9 @@ expect(response).to have_http_status(:success) - records = JSON.parse(response.body, symbolize_names: true)[:plans] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(plan.id) - expect(records.first[:code]).to eq(plan.code) + expect(json[:plans].count).to eq(1) + expect(json[:plans].first[:lago_id]).to eq(plan.id) + expect(json[:plans].first[:code]).to eq(plan.code) end context 'with pagination' do @@ -291,14 +276,12 @@ expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:plans].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:plans].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end diff --git a/spec/requests/api/v1/subscriptions_spec.rb b/spec/requests/api/v1/subscriptions_spec.rb index ee529d88686..86c89603141 100644 --- a/spec/requests/api/v1/subscriptions_spec.rb +++ b/spec/requests/api/v1/subscriptions_spec.rb @@ -21,36 +21,32 @@ it 'returns a success' do post_with_token(organization, '/api/v1/subscriptions', { subscription: params }) - expect(response).to have_http_status(200) - - result = JSON.parse(response.body, symbolize_names: true)[:subscription] - - expect(result[:lago_id]).to be_present - expect(result[:external_id]).to be_present - expect(result[:external_customer_id]).to eq(customer.external_id) - expect(result[:lago_customer_id]).to eq(customer.id) - expect(result[:plan_code]).to eq(plan.code) - expect(result[:status]).to eq('active') - expect(result[:name]).to eq('subscription name') - expect(result[:started_at]).to be_present - expect(result[:billing_time]).to eq('anniversary') - expect(result[:previous_plan_code]).to be_nil - expect(result[:next_plan_code]).to be_nil - expect(result[:previous_external_id]).to be_nil - expect(result[:next_external_id]).to be_nil + expect(response).to have_http_status(:ok) + + expect(json[:subscription][:lago_id]).to be_present + expect(json[:subscription][:external_id]).to be_present + expect(json[:subscription][:external_customer_id]).to eq(customer.external_id) + expect(json[:subscription][:lago_customer_id]).to eq(customer.id) + expect(json[:subscription][:plan_code]).to eq(plan.code) + expect(json[:subscription][:status]).to eq('active') + expect(json[:subscription][:name]).to eq('subscription name') + expect(json[:subscription][:started_at]).to be_present + expect(json[:subscription][:billing_time]).to eq('anniversary') + expect(json[:subscription][:previous_plan_code]).to be_nil + expect(json[:subscription][:next_plan_code]).to be_nil + expect(json[:subscription][:previous_external_id]).to be_nil + expect(json[:subscription][:next_external_id]).to be_nil end context 'with invalid params' do let(:params) do - { - plan_code: plan.code - } + { plan_code: plan.code } end it 'returns an unprocessable_entity error' do post_with_token(organization, '/api/v1/subscriptions', { subscription: params }) - expect(response).to have_http_status(422) + expect(response).to have_http_status(:unprocessable_entity) end end end @@ -64,12 +60,9 @@ delete_with_token(organization, "/api/v1/subscriptions/#{subscription.external_id}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:subscription] - - expect(result[:lago_id]).to eq(subscription.id) - expect(result[:status]).to eq('terminated') - expect(result[:terminated_at]).to be_present + expect(json[:subscription][:lago_id]).to eq(subscription.id) + expect(json[:subscription][:status]).to eq('terminated') + expect(json[:subscription][:terminated_at]).to be_present end context 'with not existing subscription' do @@ -91,16 +84,13 @@ put_with_token(organization, "/api/v1/subscriptions/#{subscription.external_id}", { subscription: update_params }) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:subscription] - - expect(result[:lago_id]).to eq(subscription.id) - expect(result[:name]).to eq('subscription name new') + expect(json[:subscription][:lago_id]).to eq(subscription.id) + expect(json[:subscription][:name]).to eq('subscription name new') end context 'with not existing subscription' do it 'returns an not found error' do - put_with_token(organization, "/api/v1/subscriptions/invalid", { subscription: update_params }) + put_with_token(organization, '/api/v1/subscriptions/invalid', { subscription: update_params }) expect(response).to have_http_status(:not_found) end @@ -116,11 +106,8 @@ get_with_token(organization, "/api/v1/subscriptions?external_customer_id=#{customer.external_id}") expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:subscriptions] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(subscription1.id) + expect(json[:subscriptions].count).to eq(1) + expect(json[:subscriptions].first[:lago_id]).to eq(subscription1.id) end context 'with next and previous subscriptions' do @@ -149,8 +136,7 @@ it 'returns next and previous plan code' do get_with_token(organization, "/api/v1/subscriptions?external_customer_id=#{customer.external_id}") - subscription = JSON.parse(response.body, symbolize_names: true)[:subscriptions].first - + subscription = json[:subscriptions].first expect(subscription[:previous_plan_code]).to eq(previous_subscription.plan.code) expect(subscription[:next_plan_code]).to eq(next_subscription.plan.code) end @@ -158,15 +144,14 @@ it 'returns next and previous external ids' do get_with_token(organization, "/api/v1/subscriptions?external_customer_id=#{customer.external_id}") - subscription = JSON.parse(response.body, symbolize_names: true)[:subscriptions].first - + subscription = json[:subscriptions].first expect(subscription[:previous_external_id]).to eq(previous_subscription.external_id) expect(subscription[:next_external_id]).to eq(next_subscription.external_id) end end context 'with pagination' do - let(:plan2) { create(:plan, organization: organization, amount_cents: 30000) } + let(:plan2) { create(:plan, organization: organization, amount_cents: 30_000) } let(:subscription2) { create(:subscription, customer: customer, plan: plan2) } before { subscription2 } @@ -176,14 +161,12 @@ expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:subscriptions].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:subscriptions].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end diff --git a/spec/requests/api/v1/wallet_transactions_spec.rb b/spec/requests/api/v1/wallet_transactions_spec.rb index 636906d326f..4a5bbe57db0 100644 --- a/spec/requests/api/v1/wallet_transactions_spec.rb +++ b/spec/requests/api/v1/wallet_transactions_spec.rb @@ -28,18 +28,17 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:wallet_transactions] - expect(result.count).to eq(2) - expect(result.first[:lago_id]).to be_present - expect(result.second[:lago_id]).to be_present - expect(result.first[:status]).to eq('pending') - expect(result.second[:status]).to eq('settled') - expect(result.first[:lago_wallet_id]).to eq(wallet.id) - expect(result.second[:lago_wallet_id]).to eq(wallet.id) + expect(json[:wallet_transactions].count).to eq(2) + expect(json[:wallet_transactions].first[:lago_id]).to be_present + expect(json[:wallet_transactions].second[:lago_id]).to be_present + expect(json[:wallet_transactions].first[:status]).to eq('pending') + expect(json[:wallet_transactions].second[:status]).to eq('settled') + expect(json[:wallet_transactions].first[:lago_wallet_id]).to eq(wallet.id) + expect(json[:wallet_transactions].second[:lago_wallet_id]).to eq(wallet.id) end context 'when wallet does not exist' do - let(:wallet_id) { wallet.id + '123' } + let(:wallet_id) { "#{wallet.id}123" } it 'returns unprocessable_entity error' do post_with_token(organization, '/api/v1/wallet_transactions', { wallet_transaction: create_params }) diff --git a/spec/requests/api/v1/wallets_spec.rb b/spec/requests/api/v1/wallets_spec.rb index 340763b7cd0..2cc84143dfa 100644 --- a/spec/requests/api/v1/wallets_spec.rb +++ b/spec/requests/api/v1/wallets_spec.rb @@ -17,7 +17,7 @@ name: 'Wallet1', paid_credits: '10', granted_credits: '10', - expiration_date: '2022-06-06' + expiration_date: '2022-06-06', } end @@ -26,10 +26,9 @@ expect(response).to have_http_status(:success) - result = JSON.parse(response.body, symbolize_names: true)[:wallet] - expect(result[:lago_id]).to be_present - expect(result[:name]).to eq(create_params[:name]) - expect(result[:external_customer_id]).to eq(customer.external_id) + expect(json[:wallet][:lago_id]).to be_present + expect(json[:wallet][:name]).to eq(create_params[:name]) + expect(json[:wallet][:external_customer_id]).to eq(customer.external_id) end end @@ -38,24 +37,22 @@ let(:update_params) do { name: 'wallet1', - expiration_date: '2022-07-07' + expiration_date: '2022-07-07', } end before { wallet } it 'updates a wallet' do - put_with_token(organization, + put_with_token( + organization, "/api/v1/wallets/#{wallet.id}", - { wallet: update_params } + { wallet: update_params }, ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:wallet] - - expect(result[:lago_id]).to eq(wallet.id) - expect(result[:name]).to eq(update_params[:name]) + expect(json[:wallet][:lago_id]).to eq(wallet.id) + expect(json[:wallet][:name]).to eq(update_params[:name]) end context 'when wallet does not exist' do @@ -75,23 +72,17 @@ it 'returns a wallet' do get_with_token( organization, - "/api/v1/wallets/#{wallet.id}" + "/api/v1/wallets/#{wallet.id}", ) expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:wallet] - - expect(result[:lago_id]).to eq(wallet.id) - expect(result[:name]).to eq(wallet.name) + expect(json[:wallet][:lago_id]).to eq(wallet.id) + expect(json[:wallet][:name]).to eq(wallet.name) end context 'when wallet does not exist' do it 'returns not found' do - get_with_token( - organization, - "/api/v1/wallets/555" - ) + get_with_token(organization, '/api/v1/wallets/555') expect(response).to have_http_status(:not_found) end @@ -113,11 +104,8 @@ delete_with_token(organization, "/api/v1/wallets/#{wallet.id}") expect(response).to have_http_status(:success) - - result = JSON.parse(response.body, symbolize_names: true)[:wallet] - - expect(result[:lago_id]).to eq(wallet.id) - expect(result[:name]).to eq(wallet.name) + expect(json[:wallet][:lago_id]).to eq(wallet.id) + expect(json[:wallet][:name]).to eq(wallet.name) end context 'when wallet does not exist' do @@ -138,12 +126,9 @@ get_with_token(organization, "/api/v1/wallets?external_customer_id=#{customer.external_id}") expect(response).to have_http_status(:success) - - records = JSON.parse(response.body, symbolize_names: true)[:wallets] - - expect(records.count).to eq(1) - expect(records.first[:lago_id]).to eq(wallet.id) - expect(records.first[:name]).to eq(wallet.name) + expect(json[:wallets].count).to eq(1) + expect(json[:wallets].first[:lago_id]).to eq(wallet.id) + expect(json[:wallets].first[:name]).to eq(wallet.name) end context 'with pagination' do @@ -156,14 +141,12 @@ expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body, symbolize_names: true) - - expect(response_body[:wallets].count).to eq(1) - expect(response_body[:meta][:current_page]).to eq(1) - expect(response_body[:meta][:next_page]).to eq(2) - expect(response_body[:meta][:prev_page]).to eq(nil) - expect(response_body[:meta][:total_pages]).to eq(2) - expect(response_body[:meta][:total_count]).to eq(2) + expect(json[:wallets].count).to eq(1) + expect(json[:meta][:current_page]).to eq(1) + expect(json[:meta][:next_page]).to eq(2) + expect(json[:meta][:prev_page]).to eq(nil) + expect(json[:meta][:total_pages]).to eq(2) + expect(json[:meta][:total_count]).to eq(2) end end end diff --git a/spec/requests/api/v1/webhooks_spec.rb b/spec/requests/api/v1/webhooks_spec.rb index 06a594855c8..dd465c64132 100644 --- a/spec/requests/api/v1/webhooks_spec.rb +++ b/spec/requests/api/v1/webhooks_spec.rb @@ -10,7 +10,6 @@ get_with_token(organization, '/api/v1/webhooks/public_key') expect(response).to have_http_status(:success) - expect(response.body).to eq(Base64.encode64(RsaPublicKey.to_s)) end end diff --git a/spec/requests/application_spec.rb b/spec/requests/application_spec.rb index 2a167cd205c..5b69ee2d80f 100644 --- a/spec/requests/application_spec.rb +++ b/spec/requests/application_spec.rb @@ -9,11 +9,9 @@ aggregate_failures do expect(response.status).to be(200) - - json = JSON.parse(response.body) - expect(json['message']).to eq('Success') - expect(json['version']).to be_present - expect(json['github_url']).to be_present + expect(json[:message]).to eq('Success') + expect(json[:version]).to be_present + expect(json[:github_url]).to be_present end end end @@ -24,11 +22,9 @@ aggregate_failures do expect(response.status).to be(404) - - json = JSON.parse(response.body) - expect(json['status']).to eq(404) - expect(json['error']).to eq('Not Found') - expect(json['code']).to eq('resource_not_found') + expect(json[:status]).to eq(404) + expect(json[:error]).to eq('Not Found') + expect(json[:code]).to eq('resource_not_found') end end end diff --git a/spec/requests/webhooks_spec.rb b/spec/requests/webhooks_spec.rb index b1517224875..2d245977269 100644 --- a/spec/requests/webhooks_spec.rb +++ b/spec/requests/webhooks_spec.rb @@ -73,7 +73,7 @@ expect(response).to have_http_status(:bad_request) expect(PaymentProviders::StripeService).to have_received(:new) - expect(stripe_service). to have_received(:handle_incoming_webhook) + expect(stripe_service).to have_received(:handle_incoming_webhook) end end end diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index 8ed3d62c9c3..5bd4e809722 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -21,6 +21,12 @@ def delete_with_token(organization, path, params = {}, headers = {}) delete(path, params: params.to_json, headers: headers) end + def json + return response.body unless response.media_type.include?('json') + + JSON.parse(response.body, symbolize_names: true) + end + private def set_headers(organization, headers)