From 53a8acb1b71e31e5327103d457b735767acaa278 Mon Sep 17 00:00:00 2001 From: Robert Peralta Date: Tue, 23 May 2023 14:26:44 -0400 Subject: [PATCH 1/4] Make trigger_id and action_name optional for actions index endpoint Use proper path for create_action endpoint --- lib/auth0/api/v2/actions.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/auth0/api/v2/actions.rb b/lib/auth0/api/v2/actions.rb index cb4c3951..ffd7f9a2 100644 --- a/lib/auth0/api/v2/actions.rb +++ b/lib/auth0/api/v2/actions.rb @@ -16,10 +16,7 @@ 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, @@ -38,7 +35,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. From f729dc7e8a1ed3c6b0ffc3d6c52272e04e95611b Mon Sep 17 00:00:00 2001 From: Robert Peralta Date: Tue, 23 May 2023 14:37:08 -0400 Subject: [PATCH 2/4] Fix specs --- spec/lib/auth0/api/v2/actions_spec.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/spec/lib/auth0/api/v2/actions_spec.rb b/spec/lib/auth0/api/v2/actions_spec.rb index 28e1d264..a80526b6 100644 --- a/spec/lib/auth0/api/v2/actions_spec.rb +++ b/spec/lib/auth0/api/v2/actions_spec.rb @@ -27,8 +27,8 @@ }) expect do @instance.actions( - 'post-login', - 'loginHandler', + trigger_id: 'post-login', + action_name: 'loginHandler', deployed: true, per_page: 10, page: 1, @@ -37,13 +37,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 @@ -71,7 +64,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 From 7f4b1fa467f1793ed558c80381b6eb770cb2a41b Mon Sep 17 00:00:00 2001 From: Steve Hobbs Date: Fri, 8 Sep 2023 14:32:19 +0100 Subject: [PATCH 3/4] chore: update Gemfile.lock --- Gemfile.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.lock b/Gemfile.lock index fff35ec3..4d90c374 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -219,6 +219,7 @@ GEM PLATFORMS aarch64-linux arm64-darwin-21 + arm64-darwin-22 x86_64-darwin-21 x86_64-linux From cb1ade0bdc1458e2e60f59a0bdb12119592ca980 Mon Sep 17 00:00:00 2001 From: Steve Hobbs Date: Fri, 8 Sep 2023 15:03:46 +0100 Subject: [PATCH 4/4] fix(actions): reinstate position arguments as optional --- lib/auth0/api/v2/actions.rb | 7 ++++--- spec/lib/auth0/api/v2/actions_spec.rb | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/auth0/api/v2/actions.rb b/lib/auth0/api/v2/actions.rb index ffd7f9a2..6d1af603 100644 --- a/lib/auth0/api/v2/actions.rb +++ b/lib/auth0/api/v2/actions.rb @@ -16,15 +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: nil, action_name: nil, deployed: nil, per_page: nil, page: nil, installed: nil) + 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 diff --git a/spec/lib/auth0/api/v2/actions_spec.rb b/spec/lib/auth0/api/v2/actions_spec.rb index a80526b6..d1f0e5af 100644 --- a/spec/lib/auth0/api/v2/actions_spec.rb +++ b/spec/lib/auth0/api/v2/actions_spec.rb @@ -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, @@ -27,8 +44,8 @@ }) expect do @instance.actions( - trigger_id: 'post-login', - action_name: 'loginHandler', + 'post-login', + 'loginHandler', deployed: true, per_page: 10, page: 1,