Skip to content
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
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=""
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ group :test do
gem 'vcr'
gem 'webmock'
end

gem 'dotenv', groups: [:development, :test]
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ PLATFORMS
DEPENDENCIES
beyond_api!
bundler (~> 2.0)
dotenv (~> 2.7)
dotenv
factory_bot
faker (~> 2.2)
jwt
Expand Down
1 change: 0 additions & 1 deletion beyond_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.3'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'dotenv', '~> 2.7'
spec.add_development_dependency 'faker', '~> 2.2'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
Expand Down
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!;)",
# "new.email@epages.com"
# )
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(
# "baxter@example.org"
# )
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",
# "baxter2@example.org"
# )
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
21 changes: 21 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,21 @@
# 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) { 'team42-new@epages.com' }

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

after do
# # Rollback email address change
# client.trigger_change(user_id, 'en-US', user_password, user_email)
end
end
end
62 changes: 62 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,62 @@
# 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' }

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

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

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

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

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

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

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

after do
# # Rollback the username change
# client.change_username(
# user_id,
# user_password,
# user_name
# )
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'beyond_api'
require 'factory_bot'

Dotenv.load('.env.test')

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
Expand Down