1+ /// <reference types="cypress" />
2+
3+ 'use strict' ;
4+
5+ import { PaylikeTestHelper } from './test_helper.js' ;
6+
7+ export var TestMethods = {
8+
9+ /** Admin & frontend user credentials. */
10+ StoreUrl : ( Cypress . env ( 'ENV_ADMIN_URL' ) . match ( / ^ (?: h t t p (?: s ? ) : \/ \/ ) ? (?: [ ^ @ \n ] + @ ) ? (?: w w w \. ) ? ( [ ^ : \/ \n ? ] + ) / im) ) [ 0 ] ,
11+ AdminUrl : Cypress . env ( 'ENV_ADMIN_URL' ) ,
12+ RemoteVersionLogUrl : Cypress . env ( 'REMOTE_LOG_URL' ) ,
13+
14+ /** Construct some variables to be used bellow. */
15+ ShopName : 'oscommerce' ,
16+ PaylikeName : 'paylike' ,
17+ PaymentMethodsAdminUrl : '/modules.php?set=payment' ,
18+ SystemInfoAdminUrl : '/server_info.php' ,
19+
20+ /**
21+ * Login to admin backend account
22+ */
23+ loginIntoAdminBackend ( ) {
24+ cy . loginIntoAccount ( 'input[name=username]' , 'input[name=password]' , 'admin' ) ;
25+ } ,
26+ /**
27+ * Login to client|user frontend account
28+ */
29+ loginIntoClientAccount ( ) {
30+ cy . get ( 'a[id=tdb3]' ) . click ( ) ;
31+ cy . loginIntoAccount ( 'input[name=email_address]' , 'input[name=password]' , 'client' ) ;
32+ } ,
33+
34+ /**
35+ * Modify Paylike capture mode
36+ *
37+ * @param {String } captureMode
38+ */
39+ changePaylikeCaptureMode ( captureMode ) {
40+ /** Go to Paylike payment method. */
41+ cy . goToPage ( this . PaymentMethodsAdminUrl ) ;
42+
43+ /** Select Paylike. */
44+ cy . get ( '.dataTableContent' ) . contains ( this . PaylikeName , { matchCase : false } ) . click ( ) ;
45+
46+ cy . get ( '#tdb2' ) . click ( ) ;
47+
48+ /** Select capture mode. */
49+ cy . get ( `input[value=${ captureMode } ]` ) . click ( )
50+
51+ cy . get ( '#tdb2' ) . click ( ) ;
52+ } ,
53+
54+ /**
55+ * Make payment with specified currency
56+ * -- order must be process from app.paylike.io panel
57+ *
58+ * @param {String } currency
59+ */
60+ payWithSelectedCurrency ( currency ) {
61+ /** Make an instant payment. */
62+ it ( `makes a Paylike payment with "${ currency } "` , ( ) => {
63+ this . makePaymentFromFrontend ( currency ) ;
64+ } ) ;
65+ } ,
66+
67+ /**
68+ * Make an instant payment
69+ * @param {String } currency
70+ */
71+ makePaymentFromFrontend ( currency ) {
72+ /** Go to store frontend. */
73+ cy . goToPage ( this . StoreUrl ) ;
74+
75+ /** Change currency. */
76+ this . changeShopCurrency ( currency ) ;
77+
78+ cy . wait ( 500 ) ;
79+
80+ /** Select random product (products are randomize by default). */
81+ cy . get ( 'td a img' ) . first ( ) . click ( ) ;
82+
83+ cy . get ( 'button#tdb5' ) . click ( ) ;
84+
85+ /** Go to checkout. */
86+ cy . get ( '.ui-button-icon-primary.ui-icon.ui-icon-triangle-1-e' ) . first ( ) . click ( ) ;
87+
88+ /** Continue checkout. */
89+ cy . get ( 'button#tdb6' ) . click ( ) ;
90+
91+ /** Choose Paylike. */
92+ cy . get ( `input[value=${ this . PaylikeName } ]` ) . click ( ) ;
93+
94+ /** Continue checkout. */
95+ cy . get ( 'button#tdb6' ) . click ( ) ;
96+
97+ /** Get total amount. */
98+ cy . get ( ':nth-child(2) > strong' ) . then ( $grandTotal => {
99+ var expectedAmount = PaylikeTestHelper . filterAndGetAmountInMinor ( $grandTotal , currency ) ;
100+ cy . wrap ( expectedAmount ) . as ( 'expectedAmount' ) ;
101+ } ) ;
102+
103+ /** Show paylike popup. */
104+ cy . get ( '#payLikeCheckout' ) . click ( ) ;
105+
106+ /** Get paylike amount. */
107+ cy . get ( '.paylike .payment .amount' ) . then ( $paylikeAmount => {
108+ var orderTotalAmount = PaylikeTestHelper . filterAndGetAmountInMinor ( $paylikeAmount , currency ) ;
109+ cy . get ( '@expectedAmount' ) . then ( expectedAmount => {
110+ expect ( expectedAmount ) . to . eq ( orderTotalAmount ) ;
111+ } ) ;
112+ } ) ;
113+
114+ /**
115+ * Fill in Paylike popup.
116+ */
117+ PaylikeTestHelper . fillAndSubmitPaylikePopup ( ) ;
118+
119+ cy . wait ( 500 ) ;
120+
121+ cy . get ( 'h1' ) . should ( 'contain' , 'Your Order Has Been Processed!' ) ;
122+ } ,
123+
124+ /**
125+ * Change shop currency in frontend
126+ */
127+ changeShopCurrency ( currency ) {
128+ cy . get ( 'select[name=currency]' ) . select ( currency ) ;
129+ } ,
130+
131+ /**
132+ * Get Shop & Paylike versions and send log data.
133+ */
134+ logVersions ( ) {
135+ /** Go to system information. */
136+ cy . goToPage ( this . SystemInfoAdminUrl ) ;
137+
138+ cy . wait ( 1000 ) ;
139+
140+ /** Get framework version. */
141+ cy . get ( 'h1' ) . contains ( this . ShopName , { matchCase : false } ) . then ( $frameworkVersion => {
142+ var frameworkVersion = ( $frameworkVersion . text ( ) ) . replace ( / \. ? [ ^ 0 - 9 . ] / g, '' ) ;
143+ cy . wrap ( frameworkVersion ) . as ( 'frameworkVersion' ) ;
144+ } ) ;
145+
146+ // Cypress.$.ajax({
147+ // method: 'POST',
148+ // url: this.StoreUrl + '/includes/modules/paylike.php?action=getOrderTotalsData',
149+ // auth: {
150+ // username: Cypress.env('ENV_HTTP_USER'),
151+ // password: Cypress.env('ENV_HTTP_PASS')
152+ // },
153+ // }).then((resp) => {
154+ // cy.wrap(resp).as('paylikeVersion');
155+ // });
156+
157+ /** Get paylike version with request from a file. */
158+ cy . request ( {
159+ url : this . StoreUrl + '/includes/modules/payment/paylike_version.txt' ,
160+ auth : {
161+ username : Cypress . env ( 'ENV_HTTP_USER' ) ,
162+ password : Cypress . env ( 'ENV_HTTP_PASS' )
163+ } ,
164+ } ) . then ( ( resp ) => {
165+ cy . wrap ( resp . body ) . as ( 'paylikeVersion' ) ;
166+ } ) ;
167+
168+ /** Get global variables and make log data request to remote url. */
169+ cy . get ( '@frameworkVersion' ) . then ( frameworkVersion => {
170+ cy . get ( '@paylikeVersion' ) . then ( paylikeVersion => {
171+
172+ cy . request ( 'GET' , this . RemoteVersionLogUrl , {
173+ key : frameworkVersion ,
174+ tag : this . ShopName ,
175+ view : 'html' ,
176+ ecommerce : frameworkVersion ,
177+ plugin : paylikeVersion
178+ } ) . then ( ( resp ) => {
179+ expect ( resp . status ) . to . eq ( 200 ) ;
180+ } ) ;
181+ } ) ;
182+ } ) ;
183+ } ,
184+ }
0 commit comments