Skip to content

Commit

Permalink
Add parameters for pager to device_credentials method
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayu36 committed Feb 18, 2022
1 parent 64b8bfe commit 56e7d1c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/auth0/api/v2/device_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module DeviceCredentials
# * :include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
# * :user_id [string] The user_id of the devices to retrieve.
# * :type [string] Type of credentials to retrieve. Must be 'public_key', 'refresh_token' or 'rotating_refresh_token'
# * :page [integer] The page number. Zero based
# * :per_page [integer] The amount of entries per page
# * :include_totals [boolean] Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
#
# @return [json] Returns the list of existing devices for the specified client_id.
# rubocop:disable Metrics/AbcSize
Expand All @@ -22,7 +25,10 @@ def device_credentials(client_id, options = {})
include_fields: options.fetch(:include_fields, nil),
user_id: options.fetch(:user_id, nil),
client_id: client_id,
type: options.fetch(:type, nil)
type: options.fetch(:type, nil),
page: options.fetch(:page, nil),
per_page: options.fetch(:per_page, nil),
include_totals: options.fetch(:include_totals, nil)
}
raise Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
if !request_params[:type].nil? && !%w(public_key refresh_token rotating_refresh_token).include?(request_params[:type])
Expand Down
19 changes: 18 additions & 1 deletion spec/lib/auth0/api/v2/device_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,27 @@
include_fields: nil,
user_id: nil,
client_id: client_id,
type: nil
type: nil,
page: nil,
per_page: nil,
include_totals: nil
})
expect { @instance.device_credentials(client_id) }.not_to raise_error
end
it 'is expected to send get request with options to /api/v2/device-credentials' do
expect(@instance).to receive(:get).with(
'/api/v2/device-credentials', {
fields: 'name',
include_fields: true,
user_id: '1',
client_id: client_id,
type: 'rotating_refresh_token',
page: 1,
per_page: 10,
include_totals: true
})
expect { @instance.device_credentials(client_id, fields: 'name', include_fields: true, user_id: '1', type: 'rotating_refresh_token', page: 1, per_page: 10, include_totals: true) }.not_to raise_error
end
it 'is expect to raise an error when type is not one of \'public_key\', \'refresh_token\', \'rotating_refresh_token\'' do
expect { @instance.device_credentials(client_id, type: 'invalid_type') }.to raise_error(
'Type must be one of \'public_key\', \'refresh_token\', \'rotating_refresh_token\''
Expand Down

0 comments on commit 56e7d1c

Please sign in to comment.