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

[SDK-3642] feat: support complex field names in export_users #387

Merged
merged 4 commits into from
Oct 7, 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
19 changes: 15 additions & 4 deletions lib/auth0/api/v2/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def import_users(users_file, connection_id, options = {})
# :format [string] The format of the file. Valid values are: "json" and "csv".
# :limit [integer] Limit the number of users to export.
# :fields [array] A list of fields to be included in the CSV.
# This can either be an array of strings representing field names, or an object.
# If it's a string, it is mapped to the correct { name: '<field name>' } object required by the endpoint.
# If it's an object, it is passed through as-is to the endpoint.
# If omitted, a set of predefined fields will be exported.
#
# @return [json] Returns the job status and properties.
Expand Down Expand Up @@ -109,14 +112,22 @@ def jobs_path
@jobs_path ||= '/api/v2/jobs'
end

# Map array of field names for export to array of objects
# @param fields [array] Field names to be included in the export

# Map array of fields for export to array of objects
# @param fields [array] Fields to be included in the export
# This can either be an array of strings representing field names, or an object.
# If it's a string, it is mapped to the correct { name: '<field name>' } object required by the endpoint.
# If it's an object, it is passed through as-is to the endpoint.
# @return [array] Returns the fields mapped as array of objects for the export_users endpoint
def fields_for_export(fields)
return nil if fields.to_s.empty?

fields.map { |field| { name: field } }
fields.map { |field|
if field.is_a? String
{ name: field }
else
field
end
}
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/auth0/api/v2/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,31 @@
format: 'csv',
limit: 10
})

@instance.export_users(
fields: ['author'],
connection_id: 'test-connection',
format: 'csv',
limit: 10
)
end

it 'sends post to /api/v2/jobs/users-exports with export_as field' do
expect(@instance).to receive(:post).with(
'/api/v2/jobs/users-exports', {
fields: [{ name: 'author', export_as: 'writer' }],
connection_id: 'test-connection',
format: 'csv',
limit: 10
})

@instance.export_users(
fields: [{ name: 'author', export_as: 'writer' }],
connection_id: 'test-connection',
format: 'csv',
limit: 10
)
end
end

context '.send_verification_email' do
Expand Down