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

repo initialized with test cases #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 .codegenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test/unit_tests/**
test/flows/**
.gitignore
.github/**
Rakefile
Gemfile
49 changes: 49 additions & 0 deletions .github/workflows/test-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Run Tests

on:
workflow_dispatch:

permissions:
contents: read

jobs:
test-runner:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Create Environment
run: |
touch .env
echo EMAIL=${{ secrets.EMAIL }} >> .env
echo PASSWORD=${{ secrets.PASSWORD }} >> .env
echo CLIENT_ID=${{ secrets.CLIENT_ID }} >> .env
echo CLIENT_SECRET=${{ secrets.CLIENT_SECRET }} >> .env
cat .env
- name: Add Web Driver Dependency
run: |
gem install selenium-webdriver -v 4.23 && bundle add selenium-webdriver
- name: Add UI Testing Framework Dependency
run: |
gem install capybara -v 3.40 && bundle add capybara
- name: Add Minitest Dependency
run: |
gem install minitest -v 5.24 && bundle add minitest
gem install minitest-proveit -v 1.0 && bundle add minitest-proveit
- name: Add DotEnv Dependency
run: |
gem install dotenv && bundle add dotenv
- name: Run Tests
run: bundle exec rake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Gemfile.lock
.env
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
source 'https://rubygems.org'

group :test do
gem 'rake'
end

gemspec
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require "bundler/gem_tasks"
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.test_files = FileList['test/**/test_*.rb', 'spec/**/*_spec.rb']
t.warning = false
end

task :default => :test
21 changes: 21 additions & 0 deletions test/flows/flow_test_base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'json'
require 'minitest/autorun'
require 'paypal_server_sdk'
require_relative '../flows/ui_flow_executor'
require 'dotenv'

class FlowTestBase < Minitest::Test
include PaypalServerSdk
include CoreLibrary
Dotenv.load

def setup_class
_config = Configuration.new(
environment: Environment::SANDBOX,
client_credentials_auth_credentials: ClientCredentialsAuthCredentials.new(
o_auth_client_id: ENV['CLIENT_ID'],
o_auth_client_secret: ENV['CLIENT_SECRET']))
@client = Client.new(config: _config)
@ui_flow_executor = UIFlowExecutor.new
end
end
108 changes: 108 additions & 0 deletions test/flows/tests/test_add_shipping_tracker_flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
require_relative '../flow_test_base'
require 'securerandom'

class AddShippingTrackerFlowTest < FlowTestBase

def setup
setup_class
@orders_controller = @client.orders
end

def test_add_shipping_tracker_flow
request = {
'body' => OrderRequest.new(
intent: CheckoutPaymentIntent::CAPTURE,
purchase_units: [
PurchaseUnitRequest.new(
amount: AmountWithBreakdown.new(
currency_code: 'USD',
value: '10.00',
breakdown: AmountBreakdown.new(
item_total: Money.new(currency_code: 'USD', value: '10.0'),
shipping: Money.new(currency_code: 'USD', value: '0.0'),
tax_total: Money.new(currency_code: 'USD', value: '0'))
),
description: 'Camera Shop',
items: [
Item.new(
name: 'Levis 501 Selvedge STF',
unit_amount: Money.new(currency_code: 'USD', value: '5.00'),
quantity: '1',
tax: Money.new(currency_code: 'USD', value: '0.00'),
sku: '5158936'),
Item.new(
name: 'T-Shirt',
unit_amount: Money.new(currency_code: 'USD', value: '5.00'),
quantity: '1',
tax: Money.new(currency_code: 'USD', value: '0.00'),
sku: '1457432')
],
shipping: ShippingDetails.new(
address: Address.new(
country_code: 'US',
address_line_1: '123 Main Street',
admin_area_1: 'CA',
admin_area_2: 'San Jose',
postal_code: '95131'))
)
],
payment_source: PaymentSource.new(
paypal: PayPalWallet.new(
experience_context: PayPalWalletExperienceContext.new(
locale: 'en-US',
return_url: 'https://example.com/returnUrl',
cancel_url: 'https://example.com/cancelUrl')))
),
'prefer' => 'return=representation'
}
order_api_response = @orders_controller.orders_create(request)
assert_equal(200, order_api_response.status_code)

current_path = @ui_flow_executor.complete_payment(url: order_api_response.data.links.at(1).href)
assert_equal '/returnUrl', current_path

request = {
'id' => order_api_response.data.id,
'prefer' => 'return=representation'
}
captured_order_api_response = @orders_controller.orders_capture(request)
assert_equal(201, captured_order_api_response.status_code)

request = {
'id' => order_api_response.data.id,
'body' => OrderTrackerRequest.new(
capture_id: captured_order_api_response.data.purchase_units.at(0).payments.captures.at(0).id,
tracking_number: '443844607820',
carrier: ShipmentCarrier::FEDEX,
notify_payer: false,
items: [
OrderTrackerItem.new(
name: 'T-Shirt',
quantity: '1',
sku: 'sku02',
url: 'https://www.example.com/example',
image_url: 'https://www.example.com/example.jpg',
upc: UniversalProductCode.new(
type: UPCType::UPCA,
code: 'upc001'))
])
}
tracked_order_api_response = @orders_controller.orders_track_create(request)
assert_equal(201, tracked_order_api_response.status_code)

request = {
'id' => order_api_response.data.id,
'tracker_id' => tracked_order_api_response.data.purchase_units.at(0).shipping.trackers.at(0).id,
'body' => [Patch.new(op: PatchOp::REPLACE, path: '/notify_payer', value: true)]
}
order_tracker_api_response = @orders_controller.orders_trackers_patch(request)
assert_equal(204, order_tracker_api_response.status_code)

teardown
end

def teardown
@ui_flow_executor.reset_browser_session
end

end
75 changes: 75 additions & 0 deletions test/flows/tests/test_authorization_flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require_relative '../flow_test_base'
require 'securerandom'

class AuthorizationFlowTest < FlowTestBase

def setup
setup_class
@orders_controller = @client.orders
@payments_controller = @client.payments
end

def test_authorization_flow
request = {
'body' => OrderRequest.new(
intent: CheckoutPaymentIntent::AUTHORIZE,
purchase_units: [
PurchaseUnitRequest.new(
amount: AmountWithBreakdown.new(
currency_code: 'USD',
value: '25.00',
breakdown: AmountBreakdown.new(
item_total: Money.new(currency_code: 'USD', value: '25.0'),
shipping: Money.new(currency_code: 'USD', value: '0.0'),
tax_total: Money.new(currency_code: 'USD', value: '0'))
),
description: 'Clothing Shop',
items: [
Item.new(
name: 'Levis 501',
unit_amount: Money.new(currency_code: 'USD', value: '25.00'),
quantity: '1',
tax: Money.new(currency_code: 'USD', value: '0.00'),
sku: '5158936')
]
)
],
payment_source: PaymentSource.new(
paypal: PayPalWallet.new(
experience_context: PayPalWalletExperienceContext.new(
locale: 'en-US',
return_url: 'https://example.com/returnUrl',
cancel_url: 'https://example.com/cancelUrl',
landing_page: PayPalExperienceLandingPage::LOGIN)))
),
'prefer' => 'return=representation'
}

order_api_response = @orders_controller.orders_create(request)
assert_equal(200, order_api_response.status_code)

current_path = @ui_flow_executor.complete_payment(url: order_api_response.data.links.at(1).href)
assert_equal '/returnUrl', current_path

request = {
'id' => order_api_response.data.id,
'prefer' => 'return=representation'
}
authorized_order_api_response = @orders_controller.orders_authorize(request)
assert_equal(201, authorized_order_api_response.status_code)

request = {
'authorization_id' => authorized_order_api_response.data.purchase_units.at(0).payments.authorizations.at(0).id,
'prefer' => 'return=representation'
}
api_response = @payments_controller.authorizations_void(request)
assert_equal(200, api_response.status_code)

teardown
end

def teardown
@ui_flow_executor.reset_browser_session
end

end
88 changes: 88 additions & 0 deletions test/flows/tests/test_authorize_and_capture_flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require_relative '../flow_test_base'
require 'securerandom'

class AuthorizeAndCaptureFlowTest < FlowTestBase

def setup
setup_class
@orders_controller = @client.orders
@payments_controller = @client.payments
end

def test_authorize_and_capture_flow
guid = SecureRandom.uuid
request = {
'body' => OrderRequest.new(
intent: CheckoutPaymentIntent::AUTHORIZE,
purchase_units: [
PurchaseUnitRequest.new(
amount: AmountWithBreakdown.new(
currency_code: 'USD',
value: '25.00',
breakdown: AmountBreakdown.new(
item_total: Money.new(currency_code: 'USD', value: '25.0'),
shipping: Money.new(currency_code: 'USD', value: '0.0'),
tax_total: Money.new(currency_code: 'USD', value: '0'))
),
description: 'Clothing Shop',
items: [
Item.new(
name: 'Levis 501',
unit_amount: Money.new(currency_code: 'USD', value: '25.00'),
quantity: '1',
tax: Money.new(currency_code: 'USD', value: '0.00'),
sku: '5158936')
]
)
],
payment_source: PaymentSource.new(
paypal: PayPalWallet.new(
experience_context: PayPalWalletExperienceContext.new(
locale: 'en-US',
return_url: 'https://example.com/returnUrl',
cancel_url: 'https://example.com/cancelUrl',
landing_page: PayPalExperienceLandingPage::LOGIN)))
),
'pay_pal_request_id' => guid,
'pay_pal_partner_attribution_id' => 'PayPal-Partner-Attribution-Id',
'pay_pal_client_metadata_id' => 'PayPal-Client-Metadata-Id',
'prefer' => 'return=representation'
}

order_api_response = @orders_controller.orders_create(request)
assert_equal(200, order_api_response.status_code)

current_path = @ui_flow_executor.complete_payment(url: order_api_response.data.links.at(1).href)
assert_equal '/returnUrl', current_path

request = {
'id' => order_api_response.data.id,
'prefer' => 'return=representation'
}
authorized_order_api_response = @orders_controller.orders_authorize(request)
assert_equal(201, authorized_order_api_response.status_code)

request = {
'authorization_id' => authorized_order_api_response.data.purchase_units.at(0).payments.authorizations.at(0).id,
'prefer' => 'return=representation',
'body' => CaptureRequest.new(final_capture: false)
}
captured_payment_api_response = @payments_controller.authorizations_capture(request)
assert_equal(201, captured_payment_api_response.status_code)

authorized_payment_api_response = @payments_controller.authorizations_get(
authorized_order_api_response.data.purchase_units.at(0).payments.authorizations.at(0).id)
assert_equal(200, authorized_payment_api_response.status_code)
assert_equal(AuthorizationStatus::CAPTURED, authorized_payment_api_response.data.status)

captured_api_response = @payments_controller.captures_get(captured_payment_api_response.data.id)
assert_equal(200, captured_api_response.status_code)
assert_equal(CaptureStatus::COMPLETED, captured_api_response.data.status)

teardown
end

def teardown
@ui_flow_executor.reset_browser_session
end
end
Loading