-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add order checkout flow tests, add go pay mocker test module
see #3
- Loading branch information
Showing
6 changed files
with
154 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Boutique::Test | ||
module GoPayApiMocker | ||
private | ||
def go_pay_create_payment_api_call_mock | ||
result = { | ||
"id" => 123, | ||
"payment_instrument" => "PAYMENT_CARD", | ||
"gw_url" => mocked_go_pay_payment_gateway_url, | ||
} | ||
|
||
Boutique::GoPay::Api.any_instance | ||
.expects(:create_payment) | ||
.returns(result) | ||
end | ||
|
||
def go_pay_find_payment_api_call_mock(state: "PAID") | ||
result = { | ||
"id" => 123, | ||
"payment_instrument" => "PAYMENT_CARD", | ||
"state" => state, | ||
} | ||
|
||
Boutique::GoPay::Api.any_instance | ||
.expects(:find_payment) | ||
.returns(result) | ||
end | ||
|
||
def mocked_go_pay_payment_gateway_url | ||
"https://test.gopay.com" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Boutique::OrderCheckoutFlowTest < Boutique::ControllerTest | ||
include Boutique::Test::GoPayApiMocker | ||
include Devise::Test::IntegrationHelpers | ||
|
||
def setup | ||
super | ||
|
||
@product = create(:boutique_product) | ||
go_pay_create_payment_api_call_mock | ||
end | ||
|
||
test "anonymous - successful payment" do | ||
post add_order_url, params: { product_variant_id: @product.master_variant.id } | ||
assert_redirected_to edit_order_url | ||
assert_equal 1, Boutique::Order.count | ||
|
||
params = { | ||
order: { | ||
first_name: "John", | ||
last_name: "Doe", | ||
email: "[email protected]", | ||
primary_address_attributes: build(:boutique_folio_primary_address).serializable_hash, | ||
} | ||
} | ||
|
||
post confirm_order_url, params: params | ||
assert_redirected_to mocked_go_pay_payment_gateway_url | ||
|
||
go_pay_find_payment_api_call_mock | ||
get comeback_go_pay_url(id: 123) | ||
assert_redirected_to main_app.user_invitation_url | ||
end | ||
|
||
test "anonymous - unsuccessful payment" do | ||
post add_order_url, params: { product_variant_id: @product.master_variant.id } | ||
assert_redirected_to edit_order_url | ||
assert_equal 1, Boutique::Order.count | ||
|
||
params = { | ||
order: { | ||
first_name: "John", | ||
last_name: "Doe", | ||
email: "[email protected]", | ||
primary_address_attributes: build(:boutique_folio_primary_address).serializable_hash, | ||
} | ||
} | ||
|
||
post confirm_order_url, params: params | ||
assert_redirected_to mocked_go_pay_payment_gateway_url | ||
|
||
go_pay_find_payment_api_call_mock(state: "CANCELED") | ||
|
||
get comeback_go_pay_url(id: 123) | ||
assert_redirected_to order_url(Boutique::Order.first.secret_hash) | ||
end | ||
|
||
test "user - successful payment" do | ||
user = create(:folio_user) | ||
sign_in user | ||
|
||
post add_order_url, params: { product_variant_id: @product.master_variant.id } | ||
assert_redirected_to edit_order_url | ||
assert_equal 1, Boutique::Order.count | ||
|
||
params = { | ||
order: { | ||
primary_address_attributes: build(:boutique_folio_primary_address).serializable_hash, | ||
} | ||
} | ||
|
||
post confirm_order_url, params: params | ||
assert_redirected_to mocked_go_pay_payment_gateway_url | ||
|
||
go_pay_find_payment_api_call_mock | ||
|
||
get comeback_go_pay_url(id: 123) | ||
assert_redirected_to order_url(Boutique::Order.first.secret_hash) | ||
end | ||
|
||
test "user - unsuccessful payment" do | ||
user = create(:folio_user) | ||
sign_in user | ||
|
||
post add_order_url, params: { product_variant_id: @product.master_variant.id } | ||
assert_redirected_to edit_order_url | ||
assert_equal 1, Boutique::Order.count | ||
|
||
params = { | ||
order: { | ||
primary_address_attributes: build(:boutique_folio_primary_address).serializable_hash, | ||
} | ||
} | ||
|
||
post confirm_order_url, params: params | ||
assert_redirected_to mocked_go_pay_payment_gateway_url | ||
|
||
go_pay_find_payment_api_call_mock | ||
|
||
get comeback_go_pay_url(id: 123) | ||
assert_redirected_to order_url(Boutique::Order.first.secret_hash) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters