Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters for pager to device_credentials method #318

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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