Skip to content

Commit

Permalink
Make trigger_id and action_name optional for actions index endpoint (#…
Browse files Browse the repository at this point in the history
…478)

Co-authored-by: Steve Hobbs <[email protected]>
Co-authored-by: Steve Hobbs <[email protected]>
  • Loading branch information
3 people committed Sep 12, 2023
1 parent c0e0a28 commit 21a0f0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
aarch64-linux
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
Expand Down
13 changes: 6 additions & 7 deletions lib/auth0/api/v2/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ module Actions
# @param page [integer] The page number. Zero based.
# @param installed [boolean] When true, return only installed actions. When false, return only custom actions. Returns all actions by default.
# @return [json] Actions and pagination info
def actions(trigger_id, action_name, deployed: nil, per_page: nil, page: nil, installed: nil)
raise Auth0::MissingTriggerId, 'Must supply a valid trigger_id' if trigger_id.to_s.empty?
raise Auth0::MissingActionName, 'Must supply a valid action_name' if action_name.to_s.empty?

def actions(trigger_id = nil, action_name = nil, deployed: nil, per_page: nil, page: nil, installed: nil)
request_params = {
trigger_id: trigger_id,
action_name: action_name,
triggerId: trigger_id,
actionName: action_name,
deployed: deployed,
per_page: per_page,
page: page,
installed: installed
}

path = "#{actions_path}/actions"
get(path, request_params)
end
Expand All @@ -38,7 +36,8 @@ def actions(trigger_id, action_name, deployed: nil, per_page: nil, page: nil, in
# @param body [hash] See https://auth0.com/docs/api/management/v2/#!/actions/post_action for available options
# @return [json] Returns the created action.
def create_action(body = {})
post(actions_path, body)
path = "#{actions_path}/actions"
post(path, body)
end

# Retrieve the set of triggers currently available within actions. A trigger is an extensibility point to which actions can be bound.
Expand Down
30 changes: 20 additions & 10 deletions spec/lib/auth0/api/v2/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,28 @@
expect(@instance).to respond_to(:get_actions)
end

it 'is expected to support all optional arguments' do
expect(@instance).to receive(:get).with(
'/api/v2/actions/actions', {
triggerId: nil,
actionName: nil,
deployed: nil,
per_page: nil,
page: nil,
installed: nil
}
)

expect do
@instance.actions()
end.not_to raise_error
end

it 'is expected to get /api/v2/actions with custom parameters' do
expect(@instance).to receive(:get).with(
'/api/v2/actions/actions', {
trigger_id: 'post-login',
action_name: 'loginHandler',
triggerId: 'post-login',
actionName: 'loginHandler',
deployed: true,
per_page: 10,
page: 1,
Expand All @@ -37,13 +54,6 @@
end.not_to raise_error
end

it 'is expected to raise an exception when the trigger id is empty' do
expect { @instance.actions(nil, nil) }.to raise_exception(Auth0::MissingTriggerId)
end

it 'is expected to raise an exception when the action name is empty' do
expect { @instance.actions(1, nil) }.to raise_exception(Auth0::MissingActionName)
end
end

context '.action' do
Expand Down Expand Up @@ -71,7 +81,7 @@

it 'is expected to post to /api/v2/actions' do
expect(@instance).to receive(:post).with(
'/api/v2/actions', {
'/api/v2/actions/actions', {
name: 'test_org'
})
expect do
Expand Down

0 comments on commit 21a0f0c

Please sign in to comment.