Skip to content

Commit 25fa10a

Browse files
committed
Added Phoenix Cypress tests
1 parent dd85160 commit 25fa10a

4 files changed

Lines changed: 308 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/// <reference types="cypress" />
2+
3+
'use strict';
4+
5+
import { TestMethods } from '../support/test_methods.js';
6+
7+
describe('paylike plugin full test', () => {
8+
/**
9+
* Login into admin and frontend to store cookies.
10+
*/
11+
before(() => {
12+
cy.goToPage(TestMethods.StoreUrl);
13+
TestMethods.loginIntoClientAccount();
14+
cy.goToPage(Cypress.env('ENV_ADMIN_URL'));
15+
TestMethods.loginIntoAdminBackend();
16+
});
17+
18+
/**
19+
* Run this on every test case bellow
20+
* - preserve cookies between tests
21+
*/
22+
beforeEach(() => {
23+
Cypress.Cookies.defaults({
24+
preserve: (cookie) => {
25+
return true;
26+
}
27+
});
28+
});
29+
30+
let captureModes = ['Instant', 'Delayed'];
31+
let currenciesToTest = Cypress.env('ENV_CURRENCIES_TO_TEST');
32+
33+
context(`make payments in "${captureModes[0]}" mode`, () => {
34+
/** Modify Paylike settings. */
35+
it(`change Paylike capture mode to "${captureModes[0]}"`, () => {
36+
TestMethods.changePaylikeCaptureMode(captureModes[0]);
37+
});
38+
39+
/** Make Instant payments */
40+
for (var currency of currenciesToTest) {
41+
TestMethods.payWithSelectedCurrency(currency);
42+
}
43+
});
44+
45+
context(`make payments in "${captureModes[1]}" mode`, () => {
46+
/** Modify Paylike settings. */
47+
it(`change Paylike capture mode to "${captureModes[1]}"`, () => {
48+
TestMethods.changePaylikeCaptureMode(captureModes[1]);
49+
});
50+
51+
for (var currency of currenciesToTest) {
52+
/**
53+
* HARDCODED currency
54+
*/
55+
if ('USD' == currency || 'RON' == currency) {
56+
TestMethods.payWithSelectedCurrency(currency);
57+
}
58+
}
59+
});
60+
}); // describe
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="cypress" />
2+
3+
'use strict';
4+
5+
import { TestMethods } from '../support/test_methods.js';
6+
7+
describe('paylike plugin version log remotely', () => {
8+
/**
9+
* Go to backend site admin
10+
*/
11+
before(() => {
12+
cy.goToPage(Cypress.env('ENV_ADMIN_URL'));
13+
TestMethods.loginIntoAdminBackend();
14+
});
15+
16+
/** Send log after full test finished. */
17+
it('log shop & paylike versions remotely', () => {
18+
TestMethods.logVersions();
19+
});
20+
}); // describe
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference types="cypress" />
2+
3+
'use strict';
4+
5+
import { TestMethods } from '../support/test_methods.js';
6+
7+
describe('paylike plugin quick test', () => {
8+
/**
9+
* Login into admin and frontend to store cookies.
10+
*/
11+
before(() => {
12+
cy.goToPage(TestMethods.StoreUrl);
13+
TestMethods.loginIntoClientAccount();
14+
cy.goToPage(Cypress.env('ENV_ADMIN_URL'));
15+
TestMethods.loginIntoAdminBackend();
16+
});
17+
18+
/**
19+
* Run this on every test case bellow
20+
* - preserve cookies between tests
21+
*/
22+
beforeEach(() => {
23+
Cypress.Cookies.defaults({
24+
preserve: (cookie) => {
25+
return true;
26+
}
27+
});
28+
});
29+
30+
let currency = Cypress.env('ENV_CURRENCY_TO_CHANGE_WITH');
31+
let captureMode = 'Delayed';
32+
33+
/**
34+
* Modify Paylike capture mode
35+
*/
36+
it('modify Paylike settings for capture mode', () => {
37+
TestMethods.changePaylikeCaptureMode(captureMode);
38+
});
39+
40+
/** Pay and process order. */
41+
/** Capture */
42+
TestMethods.payWithSelectedCurrency(currency);
43+
44+
}); // describe
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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(/^(?:http(?:s?):\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\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

Comments
 (0)