Skip to content

Commit

Permalink
Merge pull request #1574 from yeti-switch/1573-admin-api-cdr-metadata…
Browse files Browse the repository at this point in the history
…-update

#1573, add update action for CDR API resource
  • Loading branch information
dmitry-sinina authored Oct 8, 2024
2 parents aabd007 + 5d9cf5b commit 3cfb692
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/resources/api/rest/admin/cdr/cdr_resource.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Api::Rest::Admin::Cdr::CdrResource < BaseResource
immutable
model_name 'Cdr::Cdr'
paginator :paged

Expand All @@ -18,6 +17,10 @@ def self.default_sort
[{ field: 'time_start', direction: :desc }]
end

def self.updatable_fields(_context)
[:metadata]
end

attributes :time_start,
:destination_next_rate,
:destination_fee,
Expand Down Expand Up @@ -127,7 +130,8 @@ def self.default_sort
:customer_price_no_vat,
:customer_duration,
:vendor_duration,
:destination_rate_policy_id
:destination_rate_policy_id,
:metadata

has_one :rateplan, class_name: 'Rateplan', force_routed: true
has_one :dialpeer, force_routed: true
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def dasherized_resources(name, options = {}, &block)
jsonapi_resources :incoming_registrations, only: %i[index]

namespace :cdr do
jsonapi_resources :cdrs, only: %i[index show] do
jsonapi_resources :cdrs, only: %i[index show update] do
member { get :recording }
# jsonapi_relationships
patched_jsonapi_relationships
Expand Down
31 changes: 31 additions & 0 deletions spec/acceptance/rest/admin/api/cdr/cdrs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,35 @@
expect(status).to eq(200)
end
end

patch '/api/rest/admin/cdr/cdrs/:id' do
with_options scope: :data, with_example: true do
parameter :type, 'Resource type (cdrs)', required: true
parameter :id, 'CDR ID', required: true
parameter :attributes, 'list of fields/values to update', required: true
end

jsonapi_attribute :metadata

context '200' do
let(:id) { create(:cdr).id }

example 'Update an CDR' do
request = {
data: {
id: id,
type: 'cdrs',
attributes: {
metadata: { some_json: 'some value' }
}
}
}

do_request(request)

expect(status).to eq(200)
expect(JSON.parse(response_body).dig('data', 'attributes', 'metadata')).to eq 'some_json' => 'some value'
end
end
end
end
7 changes: 4 additions & 3 deletions spec/controllers/api/rest/admin/cdr/cdrs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@
'customer-price-no-vat' => cdr.customer_price_no_vat,
'customer-duration' => cdr.customer_duration,
'vendor-duration' => cdr.vendor_duration,
'destination-rate-policy-id' => cdr.destination_rate_policy_id
'destination-rate-policy-id' => cdr.destination_rate_policy_id,
'metadata' => nil
},
'relationships' => hash_including(
'rateplan' => hash_including(
Expand Down Expand Up @@ -769,8 +770,8 @@
end

describe 'PATCH update' do
it 'PATCH should not be routable', type: :routing do
expect(patch: '/api/rest/admin/cdr/cdrs/123').to_not be_routable
it 'PATCH should be routable', type: :routing do
expect(patch: '/api/rest/admin/cdr/cdrs/123').to be_routable
end
end

Expand Down

0 comments on commit 3cfb692

Please sign in to comment.