From a30a8867a32fbbce84c389dd044f0ab47caa499e Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Fri, 7 Feb 2020 12:11:49 +0100 Subject: [PATCH] Chore: Increase test coverage for accounts controller (#475) --- .../api/v1/accounts_controller_spec.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 436f6f234..cf9ec26cc 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -9,10 +9,11 @@ RSpec.describe 'Accounts API', type: :request do before do allow(AccountBuilder).to receive(:new).and_return(account_builder) - allow(account_builder).to receive(:perform).and_return(user) end it 'calls account builder' do + allow(account_builder).to receive(:perform).and_return(user) + params = { account_name: 'test', email: email } post api_v1_accounts_url, @@ -23,6 +24,21 @@ RSpec.describe 'Accounts API', type: :request do expect(account_builder).to have_received(:perform) expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid') end + + it 'renders error response on invalid params' do + allow(account_builder).to receive(:perform).and_return(nil) + + params = { account_name: nil, email: nil } + + post api_v1_accounts_url, + params: params, + as: :json + + expect(AccountBuilder).to have_received(:new).with(params) + expect(account_builder).to have_received(:perform) + expect(response).to have_http_status(:forbidden) + expect(response.body).to eq({ message: I18n.t('errors.signup.failed') }.to_json) + end end end end