Skip to content

Commit 969279f

Browse files
committed
Added Cypress tests related files
1 parent d2556fd commit 969279f

17 files changed

Lines changed: 4884 additions & 0 deletions

.circleci/config.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# to use orbs, must use version >= 2.1
2+
version: 2.1
3+
orbs:
4+
# import Cypress orb by specifying an exact version x.y.z
5+
# or the latest version 1.x.x using "@1" syntax
6+
cypress: cypress-io/cypress@1
7+
workflows:
8+
build:
9+
jobs:
10+
# "cypress" is the name of the imported orb
11+
# "run" is the name of the job defined in Cypress orb
12+
- cypress/run:
13+
name: Run_QUICK_tests
14+
context:
15+
- paylike
16+
spec: cypress/integration/quick_test.js
17+
filters:
18+
branches:
19+
only:
20+
- master
21+
- cypress/run:
22+
name: Run_FULL_tests
23+
requires:
24+
- Run_QUICK_tests
25+
context:
26+
- paylike
27+
spec: cypress/integration/full_test.js
28+
filters:
29+
branches:
30+
only:
31+
- master
32+
# the following must run after all test passed
33+
# to show latest supported version in repository readme.md file
34+
- cypress/run:
35+
name: Run_LOG_VERSION_remotely
36+
requires:
37+
- Run_FULL_tests
38+
context:
39+
- paylike
40+
spec: cypress/integration/log_version.js
41+
filters:
42+
branches:
43+
only:
44+
- master

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea
2+
.DS_Store
3+
.env
4+
.env.production
5+
/vendor
6+
!/*/vendor
7+
logs
8+
git-hooks
9+
node_modules
10+
cypress.env.json

Testing.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#Testing with Cypress
2+
3+
As you can see the plugin is bundled with Cypress testing on this repository. You can use the tests, if you have some experience with testing.
4+
5+
***DO NOT USE IN PRODUCTION, THE TESTS MODIFY SETTINGS AND CREATE ORDERS***
6+
7+
## Requirements
8+
9+
* A framework/shop installation is required, in which you need to have the sample theme installed and products displayed on the homepage.
10+
* You need to have Paylike module installed and configured (**test keys** required)
11+
* You need to have some other currencies configured in store, then set them in `cypress.env.json` file (these will be used to make payments with every currency specified)
12+
* You also need to have an account with previous purchases for which you set the credentials in the `cypress.env.json` file
13+
* *For testing purpose, product stock management and sending order emails need to be disabled (if applicable).*
14+
15+
## Getting started
16+
17+
1. Run following commands into plugin folder (as in this repo)
18+
19+
```bash
20+
npm install cypress --save-dev
21+
```
22+
23+
2. Copy and rename `cypress.env.json.example` file in the root folder and fill the data as explained bellow:
24+
```json
25+
{
26+
"ENV_HTTP_AUTH_ENABLED": false, // 'true' if you have HTTP auth when accessing website
27+
"ENV_HTTP_USER": "", // if you have HTTP auth when accessing website
28+
"ENV_HTTP_PASS": "",
29+
"ENV_ADMIN_URL": "", // like http(s)://baseUrl/administrator
30+
"ENV_CLIENT_USER": "", // frontend user
31+
"ENV_CLIENT_PASS": "",
32+
"ENV_ADMIN_USER": "", // admin user
33+
"ENV_ADMIN_PASS": "",
34+
"REMOTE_LOG_URL": "", // if you want to send log information about framework/shop & paylike module versions
35+
"ENV_CURRENCY_TO_CHANGE_WITH": "USD",
36+
"ENV_CURRENCIES_TO_TEST": ["USD", "EUR"], // currencies used to make payments with in Full test
37+
"ENV_CARD_NUMBER": 4100000000000000,
38+
"ENV_CARD_EXPIRY": 1226,
39+
"ENV_CARD_CVV": 654
40+
}
41+
```
42+
43+
3. Start the Cypress testing server.
44+
```bash
45+
npx cypress open
46+
```
47+
4. In the interface, we can choose which test to run
48+
49+
## Getting Problems?
50+
51+
Since this is a frontend test, its not always consistent, due to delays or some glitches regarding overlapping elements. If you can't get over an issue please open an issue and we'll take a look.

cypress.env.json.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ENV_HTTP_AUTH_ENABLED": false,
3+
"ENV_HTTP_USER": "",
4+
"ENV_HTTP_PASS": "",
5+
"ENV_ADMIN_URL": "",
6+
"ENV_CLIENT_USER": "",
7+
"ENV_CLIENT_PASS": "",
8+
"ENV_ADMIN_USER": "",
9+
"ENV_ADMIN_PASS": "",
10+
"REMOTE_LOG_URL": "",
11+
"ENV_CURRENCY_TO_CHANGE_WITH": "USD",
12+
"ENV_CURRENCIES_TO_TEST": ["USD", "EUR"],
13+
"ENV_CARD_NUMBER": 4100000000000000,
14+
"ENV_CARD_EXPIRY": 1226,
15+
"ENV_CARD_CVV": 654
16+
}

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/full_test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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(Cypress.env('ENV_ADMIN_URL'));
13+
TestMethods.loginIntoAdminBackend();
14+
cy.goToPage(TestMethods.StoreUrl);
15+
TestMethods.loginIntoClientAccount();
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, 'refund');
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, 'capture');
57+
/** In "delayed" mode we check "void" action too. */
58+
TestMethods.payWithSelectedCurrency(currency, 'void');
59+
}
60+
}
61+
});
62+
}); // describe

cypress/integration/log_version.js

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

cypress/integration/quick_test.js

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 quick test', () => {
8+
/**
9+
* Login into admin and frontend to store cookies.
10+
*/
11+
before(() => {
12+
cy.goToPage(Cypress.env('ENV_ADMIN_URL'));
13+
TestMethods.loginIntoAdminBackend();
14+
cy.goToPage(TestMethods.StoreUrl);
15+
TestMethods.loginIntoClientAccount();
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, 'capture');
43+
44+
/** Refund last created order (previously captured). */
45+
it('Process last order captured from admin panel to be refunded', () => {
46+
TestMethods.processOrderFromAdmin('refund');
47+
});
48+
49+
/** Capture */
50+
TestMethods.payWithSelectedCurrency(currency, 'capture');
51+
52+
/** Partial refund last created order (previously captured). */
53+
it('Process last order captured from admin panel to be refunded', () => {
54+
TestMethods.processOrderFromAdmin('refund', /*partialAmount*/ true);
55+
});
56+
57+
/** Void */
58+
TestMethods.payWithSelectedCurrency(currency, 'void');
59+
60+
}); // describe

cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

0 commit comments

Comments
 (0)