Skip to content

Commit

Permalink
Allow to manage uuid and external_id via admin API. refs #370 (#377)
Browse files Browse the repository at this point in the history
Allow to manage uuid and external_id of billing account via admin API. closes #370
  • Loading branch information
dmitry-sinina committed Oct 2, 2018
1 parent 4a61c13 commit bd1850c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/resources/api/rest/admin/account_resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Api::Rest::Admin::AccountResource < ::BaseResource
attributes :name, :min_balance, :max_balance, :external_id,
attributes :name,
:balance, :min_balance, :max_balance,
:balance_low_threshold, :balance_high_threshold, :send_balance_notifications_to,
:external_id, :uuid,
:origination_capacity, :termination_capacity, :send_invoices_to

has_one :contractor
Expand All @@ -24,6 +26,8 @@ def send_balance_notifications_to=(value)
def self.updatable_fields(_context)
[
:name,
:uuid,
:external_id,
:min_balance,
:max_balance,
:balance_low_threshold,
Expand Down
28 changes: 22 additions & 6 deletions spec/controllers/api/rest/admin/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
it { expect(response_data['id']).to eq(account.id.to_s) }
it 'has balance threshold attributes' do
expect(response_data['attributes']).to include(
'name',
'balance','min-balance', 'max-balance',
'uuid',
'external-id',
'origination-capacity', 'termination-capacity', 'send-invoices-to',
'balance-low-threshold',
'balance-high-threshold',
'send-balance-notifications-to')
'send-balance-notifications-to'
)
end
end

Expand All @@ -63,13 +69,17 @@
context 'when attributes are valid' do
let(:attributes) do
{
name: 'name',
name: 'name',
'min-balance': 1,
'external-id': 100,
'uuid': '29161666-c29c-11e8-a11d-a088b4454590',
'max-balance': 10,
'balance-low-threshold': 90,
'balance-high-threshold': 95,
'send-balance-notifications-to': Array.wrap(Billing::Contact.collection.first.id)
'send-balance-notifications-to': Array.wrap(Billing::Contact.collection.first.id),
'send-invoices-to': Billing::Contact.collection.first.id,
'origination-capacity': 10,
'termination-capacity': 3
}
end

Expand Down Expand Up @@ -106,10 +116,16 @@
let(:attributes) do
{
name: 'name',
'external-id': 110,
'uuid': '5d24297a-c29c-11e8-a11d-a088b4454590',
'min-balance': -100,
'max-balance': 100,
'balance-low-threshold': 90,
'balance-high-threshold': 95,
'send-balance-notifications-to': Billing::Contact.collection.first.id,
'send-invoices-to': Billing::Contact.collection.first.id
'send-invoices-to': Billing::Contact.collection.first.id,
'origination-capacity': 10,
'termination-capacity': 3
}
end

Expand All @@ -125,10 +141,10 @@
end

context 'when attributes are not updatable' do
let(:attributes) { { 'external-id': 200 } }
let(:attributes) { { 'balance': 2100.2 } }

it { expect(response.status).to eq(400) }
it { expect(account.reload.external_id).to_not eq(200) }
it { expect(account.reload.external_id).to_not eq(2100.2) }
end
end

Expand Down

0 comments on commit bd1850c

Please sign in to comment.