Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions .env.test.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
API_URL=""

CLIENT_ID=""
CLIENT_SECRET=""
REFRESH_TOKEN=""

COCKPIT_USER_ID=""
COCKPIT_USER_NAME=""
COCKPIT_USER_EMAIL=""
COCKPIT_USER_PASSWORD=""
36 changes: 36 additions & 0 deletions lib/beyond_api/services/authentication/email_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module BeyondApi
module Authentication
# @example How to instantiate a client
# @client = BeyondApi::Authentication::EmailAddress.new(
# api_url: 'https://example.com/api',
# access_token: 'your_token'
# )
class EmailAddress < BaseService
# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#trigger_email_address_change
#
# @option params [Integer] :user_id
# @option params [String] :locale defines the language of the confirmation email is to be sent.
# @option params [String] :current_password the current password of the user account.
# @option params [String] :new_email the new email address for the user to set.
#
# @example
# @client.trigger_change(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "en-US",
# "GoodPassword01!;)",
# "[email protected]"
# )
def trigger_change(user_id, locale, current_password, new_email)
post(
"users/#{user_id}/change-email-request",
{ current_password:, new_email: }, # body
locale # query params
)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/beyond_api/services/authentication/signer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Signer < BaseService
# @see https://developer.epages.com/beyond-docs/#list_signers
#
# @return [Hash]
# #
#
# @example
# @client.all
def all
Expand Down
92 changes: 92 additions & 0 deletions lib/beyond_api/services/authentication/user_and_password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

module BeyondApi
module Authentication
# @example How to instantiate a client
# @client = BeyondApi::Authentication::UserAndPassword.new(
# api_url: 'https://example.com/api',
# access_token: 'your_token'
# )
class UserAndPassword < BaseService
# Verify a password against the password guidelines.
#
# @see https://developer.epages.com/beyond-docs/#verify_password
#
# @option params [Integer] :user_role the type of user. Can be one of merchant, support, or customer.
# @option params [String] :password the password that needs to be verified.
#
# @example
# @client.verify_password(
# "merchant",
# "ValidPassword!"
# )
def verify_password(user_role, password)
post(
'users/verify-password',
{ password: }, # body
user_role # query params
)
end

# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#change_password
#
# @option params [Integer] :user_id
# @option params [String] :current_password the current password of the user. This is verified before the password change.
# @option params [String] :new_password the new password to set in order to change the password.
#
# @example
# @client.change_password(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "GoodPassword01!;)",
# "ValidPassword123"
# )
def change_password(user_id, current_password, new_password)
post(
"users/#{user_id}/change-password",
{ current_password:, new_password: } # body
)
end

# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#trigger_password_reset_email
#
# @option params [String] :email the email address of the user account.
#
# @example
# @client.password_reset_email(
# "[email protected]"
# )
def password_reset_email(email)
post(
'users/reset-password-request',
{ email: } # body
)
end

# Change the username of a user.
#
# @see https://developer.epages.com/beyond-docs/#change_username
#
# @option params [Integer] :user_id the email address of the user account.
# @option params [String] :current_password The current password of the user. This is verified before the username change.
# @option params [String] :new_username The new username to set in order to change the username.
#
# @example
# @client.change_username(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "ValidPassword123",
# "[email protected]"
# )
def change_username(user_id, current_password, new_username)
post(
"users/#{user_id}/change-username",
{ current_password:, new_username: }, # body
user_role # query params
)
end
end
end
end
22 changes: 22 additions & 0 deletions spec/beyond_api/services/authentication/email_address_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

RSpec.describe BeyondApi::Authentication::EmailAddress, vcr: true do
let(:client) { described_class.new(api_url: ENV.fetch('API_URL', nil), access_token: beyond_access_token) }

let(:user_id) { ENV.fetch('COCKPIT_USER_ID', nil) }
let(:user_email) { ENV.fetch('COCKPIT_USER_EMAIL', nil) }
let(:user_password) { ENV.fetch('COCKPIT_USER_PASSWORD', nil) }

let(:new_email) { '[email protected]' }

describe '#trigger_change' do
it 'change email address' do
# client.trigger_change(user_id, 'en-US', user_password, new_email)
end

after do
# # Rollback email address change
# client.trigger_change(user_id, 'en-US', user_password, user_email)
end
end
end
66 changes: 66 additions & 0 deletions spec/beyond_api/services/authentication/user_and_password_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

RSpec.describe BeyondApi::Authentication::UserAndPassword, vcr: true do
let(:client) { described_class.new(api_url: ENV.fetch('API_URL', nil), access_token: beyond_access_token) }

let(:user_id) { ENV.fetch('COCKPIT_USER_ID', nil) }
let(:user_name) { ENV.fetch('COCKPIT_USER_NAME', nil) }
let(:user_email) { ENV.fetch('COCKPIT_USER_EMAIL', nil) }
let(:user_password) { ENV.fetch('COCKPIT_USER_PASSWORD', nil) }

describe '#verify_password' do
let(:new_password) { 'ValidPassword123' }

it 'sends a post request with the correct parameters' do
# client.verify_password('merchant', new_password)
end
end

describe '#change_password' do
let(:new_password) { 'ValidPassword123' }

it 'sends a post request with the correct parameters' do
# client.change_password(
# user_id,
# user_password,
# new_password
# )
end

after do
# # Rollback the password change
# client.change_password(
# user_id,
# new_password,
# user_password
# )
end
end

describe '#password_reset_email' do
it 'sends a post request with the correct parameters' do
# client.password_reset_email(user_email)
end
end

describe '#change_username' do
let(:new_name) { 'test-user' }

it 'sends a post request with the correct parameters' do
# client.change_username(
# user_id,
# user_password,
# new_name
# )
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the tests like follows (I just put one example):

# client.change_username(
#   user_id,
#   user_password,
#   new_name
# )
it 'sends a post request with the correct parameters'

I believe that writing an it statement without a block displays a "Pending" message when running the tests.


after do
# # Rollback the username change
# client.change_username(
# user_id,
# user_password,
# user_name
# )
end
end
end