Skip to content

Commit

Permalink
Test 3d secure auth bypassing web-mock
Browse files Browse the repository at this point in the history
Test 3d secure auth bypassing web-mock
  • Loading branch information
WencesLlobet authored Jun 9, 2020
2 parents 0dac502 + 866f190 commit 7cd8fff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ pom.xml.asc
.hg/
.idea
zebra.iml
.webdrivers

3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
:license {:name "The MIT License"
:url "https://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.9.0"]
[com.stripe/stripe-java "19.12.0"]]
[com.stripe/stripe-java "19.12.0"]
[webdriver "0.15.0"]]
:plugins [[jonase/eastwood "0.2.5"]
[lein-eftest "0.5.3"]
[lein-changelog "0.3.2"]
Expand Down
36 changes: 25 additions & 11 deletions test/zebra/payment_intents_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
[clojure.string :as str]
[zebra.payment-methods :as payment-methods]
[zebra.payment-intents :as payment-intent]
[webdriver.core :refer :all]
[zebra.helpers.constants :refer [api-key tokens]]))


(deftest create-payment-intent
(let [payment-intent (payment-intent/create
{:amount 2000
Expand Down Expand Up @@ -65,17 +67,29 @@

api-key)]

(testing "should create a valid payment intent"
(is (str/starts-with? (:id payment-intent) "pi_"))
(is (= (:object payment-intent) "payment_intent"))
(is (= (:status payment-intent) "requires_action"))
(is (= (:confirmation_method payment-intent) "automatic"))
(is (= (:payment_method_types payment-intent) ["card"]))
(is (vector? (:payment_method_types payment-intent)))
(is (= (:amount payment-intent) 1234))
(is (= (:currency payment-intent) "gbp"))
(is (= (:payment_method payment-intent) (:id payment-method)))
(is (= (:type (:next_action payment-intent)) "redirect_to_url")))))
(do
(def driver (create-driver {:driver-type :firefox :driver-args ["--headless"]}))
(to driver (:url (:redirect_to_url (:next_action payment-intent))))
(wait-for-element driver :name "__privateStripeFrame4")
(iframe driver "__privateStripeFrame4")
(wait-for-element driver :name "stripe-challenge-frame")
(iframe driver "stripe-challenge-frame")
(send-keys (wait-for-element driver :xpath "//*[@id=\"test-source-authorize-3ds\"]") (. org.openqa.selenium.Keys ENTER)))
(Thread/sleep 500)

(let [payment-intent-after-auth (payment-intent/retrieve (:id payment-intent) api-key)]
(testing "should create a valid payment intent"
(is (str/starts-with? (:id payment-intent-after-auth) "pi_"))
(is (= (:object payment-intent-after-auth) "payment_intent"))
(is (not (= (:status payment-intent-after-auth) "requires_action")))
(is (= (:confirmation_method payment-intent-after-auth) "automatic"))
(is (= (:payment_method_types payment-intent-after-auth) ["card"]))
(is (vector? (:payment_method_types payment-intent-after-auth)))
(is (= (:amount payment-intent-after-auth) 1234))
(is (= (:currency payment-intent-after-auth) "gbp"))
(is (= (:payment_method payment-intent-after-auth) (:id payment-method)))
(is (= (:type (:next_action payment-intent-after-auth)) nil))))
))

(deftest retrieve-payment-intent
(let [payment-intent (payment-intent/create
Expand Down

0 comments on commit 7cd8fff

Please sign in to comment.