forked from weDevsOfficial/wepos
-
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 E2E_API tests (weDevsOfficial#154)
* Initialize test suite * Add basepage * Add e2e setup tests * Add e2e coverage * Add testdata * Add wepos settings tests * Add receipts tests * Add license tests * Add outlet tests * Add report tests * Add pos tests * Add pos sidebar tests * Add resetsite teardown * Add e2e feature map * Add git action workflow * Add API endpoints, payloads, & schemas * Add api setup tests * Add api coverage * Add products api tests * Add orders api tests * Add ordernote api tests * Add settings api tests * Add receipts api tests * Add customers api tests * Add payment api tests * Add outlet api tests * Add counters api tests * Add coupons api tests * Add cashiers api tests * fix lodash/findIndex reference * Fix code reviews
- Loading branch information
1 parent
c0a2a58
commit 32aa76e
Showing
70 changed files
with
20,257 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
name: E2E_API Tests | ||
|
||
on: | ||
# workflow will run daily at 8:00 AM BDT (2:00 AM UTC) | ||
schedule: | ||
- cron: 0 2 * * * | ||
# workflow will trigger on pull request | ||
pull_request: | ||
branches: [develop] | ||
# workflow will trigger on push to develop branch | ||
push: | ||
branches: [develop] | ||
|
||
# workflow can be manually triggered | ||
workflow_dispatch: | ||
inputs: | ||
testsuite: | ||
description: Choose which test suite to run | ||
default: All | ||
type: choice | ||
options: | ||
- E2E | ||
- API | ||
- All | ||
|
||
# Cancels all previous workflow runs for pull requests that have not completed. | ||
concurrency: | ||
# The concurrency group contains the workflow name and the branch name for pull requests or the commit hash for any other events. | ||
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
# workflow permissions | ||
permissions: | ||
checks: write | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
# workflow environment variables | ||
env: | ||
ADMIN: admin | ||
ADMIN_PASSWORD: password | ||
CASHIER: admin2 | ||
CUSTOMER: customer1 | ||
USER_PASSWORD: 01wepos01 | ||
BASE_URL: http://localhost:9999 | ||
CI: true | ||
FORCE_COLOR: 1 | ||
DB_HOST_NAME: localhost | ||
DB_USER_NAME: root | ||
DB_USER_PASSWORD: password | ||
DATABASE: tests-wordpress | ||
DB_PREFIX: wp | ||
PR_NUMBER: ${{ github.event.number }} | ||
SHA: ${{ github.event.pull_request.head.sha }} | ||
SYSTEM_INFO: ./tests/pw/playwright/systemInfo.json | ||
API_TEST_RESULT: ./tests/pw/playwright-report/api/summary-report/results.json | ||
E2E_TEST_RESULT: ./tests/pw/playwright-report/e2e/summary-report/results.json | ||
API_COVERAGE: ./tests/pw/playwright-report/api/coverage-report/coverage.json | ||
E2E_COVERAGE: ./tests/pw/playwright-report/e2e/coverage-report/coverage.json | ||
|
||
jobs: | ||
tests: | ||
name: e2e_api tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout testing repo | ||
id: clone-wepos-lite | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use desired version of NodeJS | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
|
||
- name: Setup PHP with tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "7.4" | ||
tools: composer:v1 | ||
|
||
- name: Composer install and build (Wepos-lite) | ||
run: | | ||
composer i --no-dev -o || composer update --no-dev -o | ||
- name: Npm install and build (Wepos-lite) | ||
run: | | ||
npm ci || npm i | ||
npm run build | ||
# Install test dependencies | ||
- name: Install test dependencies | ||
working-directory: tests/pw | ||
run: | | ||
npm ci || npm i | ||
# Create wp debuglog file | ||
- name: Create wp debuglog file | ||
id: debug-log | ||
working-directory: tests/pw | ||
run: | | ||
mkdir -p wp-data && touch wp-data/debug.log | ||
# Start wordpress environment | ||
- name: Start WordPress Env | ||
id: wp-env | ||
uses: nick-fields/retry@v3 | ||
with: | ||
timeout_minutes: 4 | ||
max_attempts: 2 | ||
retry_on: error | ||
command: | | ||
cd tests/pw | ||
npm run start:env | ||
# Grab test db port | ||
- name: Get Test DB PORT | ||
id: db-port | ||
working-directory: tests/pw | ||
run: | | ||
echo "DB_PORT=$(docker ps -f ancestor='mariadb:lts' -f name='tests-mysql' --format='{{.Ports}}' | sed -E 's/.*:(.*)->.*/\1/')" >> $GITHUB_ENV | ||
# db port | ||
- name: DB PORT | ||
working-directory: tests/pw | ||
run: | | ||
echo "The value of test DB_PORT is ${{ env.DB_PORT }}" | ||
# Set permalink structure | ||
- name: Set Permalink structure | ||
working-directory: tests/pw | ||
run: | | ||
npm run wp-env run tests-cli wp rewrite structure /%postname%/ | ||
# Activate theme | ||
- name: Activate theme:Storefront | ||
working-directory: tests/pw | ||
run: | | ||
npm run wp-env run tests-cli wp theme activate storefront | ||
# Get Playwright version | ||
- name: Get installed Playwright version | ||
id: playwright-version | ||
working-directory: tests/pw | ||
run: | | ||
echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test --json | jq --raw-output '.dependencies["@playwright/test"].version')" >> $GITHUB_ENV | ||
# Cache browser binaries, cache key is based on Playwright version and OS | ||
- name: Cache playwright binaries | ||
id: playwright-cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cache/ms-playwright | ||
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }} | ||
restore-keys: | | ||
${{ runner.os }}-playwright- | ||
# Install browser binaries & OS dependencies if cache missed | ||
- name: Install Playwright browser binaries & OS dependencies | ||
id: pw-install | ||
if: steps.playwright-cache.outputs.cache-hit != 'true' | ||
working-directory: tests/pw | ||
run: | | ||
npm run pw:browser-with-deps | ||
# # Install only the OS dependencies if cache hit not needed | ||
# - name: Install Playwright OS dependencies | ||
# if: steps.playwright-cache.outputs.cache-hit == 'true' | ||
# working-directory: tests/pw | ||
# run: | | ||
# npm run pw:deps-only | ||
|
||
# Run e2e tests | ||
- name: 🧪 Running the e2e tests | ||
id: e2e-test | ||
if: success() && (github.event_name != 'workflow_dispatch' || ( github.event_name == 'workflow_dispatch' && (github.event.inputs.testsuite == 'E2E' || github.event.inputs.testsuite == 'All'))) | ||
timeout-minutes: 40 | ||
working-directory: tests/pw | ||
run: | | ||
npm run test:e2e:lite | ||
- name: 🧪 Running e2e coverage | ||
if: always() && (steps.e2e-test.outcome == 'success' || steps.e2e-test.outcome == 'failure') | ||
working-directory: tests/pw | ||
run: | | ||
npm run e2e_coverage | ||
# Run API tests | ||
- name: 🧪 Running the api tests | ||
id: api-test | ||
if: always() && steps.db-port.outcome == 'success' && ( github.event_name != 'workflow_dispatch' || ( github.event_name == 'workflow_dispatch' && (github.event.inputs.testsuite == 'API' || github.event.inputs.testsuite == 'All'))) | ||
timeout-minutes: 5 | ||
working-directory: tests/pw | ||
run: | | ||
npm run test:api:lite | ||
# Prepare test summary | ||
- name: Prepare test summary | ||
id: prepare-test-summary | ||
uses: actions/github-script@v7 | ||
if: always() && steps.clone-wepos-lite.outcome == 'success' | ||
with: | ||
result-encoding: string | ||
script: | | ||
const script = require("./tests/pw/utils/gitTestSummary.ts") | ||
return await script({github, context, core}) | ||
# # Find PR comment | ||
# - name: Find PR comment by github-actions[bot] | ||
# uses: peter-evans/find-comment@v3 | ||
# id: find-comment | ||
# if: github.event_name == 'pull_request' | ||
# with: | ||
# issue-number: ${{ github.event.pull_request.number }} | ||
# comment-author: 'github-actions[bot]' | ||
# body-includes: Tests Summary | ||
|
||
# # Post test summary as PR comment | ||
# - name: Create or update PR comment | ||
# uses: peter-evans/create-or-update-comment@v4 | ||
# if: github.event_name == 'pull_request' | ||
# with: | ||
# comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
# issue-number: ${{ github.event.pull_request.number }} | ||
# body: ${{ steps.prepare-test-summary.outputs.result }} | ||
# reactions: hooray | ||
# edit-mode: replace | ||
|
||
# Backup Database | ||
- name: Backup Database | ||
if: always() && steps.db-port.outcome == 'success' | ||
working-directory: tests/pw | ||
run: | | ||
npm run wp-env run tests-cli wp db export wp-data/db.sql | ||
# Upload artifacts | ||
- name: Archive test artifacts (screenshots, HTML snapshots, Reports) | ||
uses: actions/upload-artifact@v4 | ||
if: always() && steps.debug-log.outcome == 'success' | ||
with: | ||
name: test-artifact | ||
path: | | ||
tests/pw/wp-data | ||
tests/pw/playwright | ||
tests/pw/playwright-report | ||
if-no-files-found: ignore | ||
retention-days: 30 |
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,24 @@ | ||
# Plugin Configuration | ||
ADMIN=John_Doe [Admin username] | ||
ADMIN_PASSWORD=AdminPass123 [Password for the admin account] | ||
CASHIER=Jhonathon_Smith [Cashier username] | ||
CUSTOMER=Michael_Williams [Customer username] | ||
USER_PASSWORD=Passw0rd123 [Password for all other users] | ||
LICENSE_KEY=ABCD1234EFGH5678 [wepos License key] | ||
WEPOS_PRO=true [wepos pro active status] | ||
|
||
# Playwright Configuration | ||
BASE_URL=https://example.com [Base URL of the test site] | ||
CI=true [CI/CD environment indicator] | ||
SLOWMO=10 [Slow down test execution by provided seconds] [optional] | ||
NO_SETUP=true [Whether not to run setup tests before actual tests] [optional] | ||
LOCAL=true [Local testing indicator] [optional] | ||
SITE_PATH=/users/rk/sites/wepos [Path of the local test site][only for local testing] | ||
|
||
# Database Configuration | ||
DB_HOST_NAME=localhost [Database server hostname or IP address] | ||
DB_USER_NAME=dbuser [Database username] | ||
DB_USER_PASSWORD=dbpassword [Database user password] | ||
DATABASE=mywpdb [Database name] | ||
DB_PORT=3306 [Database connection port] | ||
DB_PREFIX=wp [Prefix for database tables] |
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,21 @@ | ||
# Playwright Specific | ||
node_modules/ | ||
playwright/ | ||
playwright-report | ||
test-results/ | ||
summary.json | ||
types/ | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
|
||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Docs files | ||
*_spec3.json | ||
|
||
|
||
# Custom files | ||
TODO.md |
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,39 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", // recommended, recommended-type-checked, strict, strict-type-checked | ||
// "plugin:@typescript-eslint/recommended-type-checked", // for ts typed check | ||
// "plugin:@typescript-eslint/stylistic", // stylistic, stylistic-type-checked | ||
// "plugin:@typescript-eslint/stylistic-type-checked", // for ts typed check | ||
"plugin:playwright/recommended", | ||
"prettier", | ||
], | ||
"plugins": ["@typescript-eslint"], | ||
"parser": "@typescript-eslint/parser", | ||
// for ts typed check | ||
// "parserOptions": { | ||
// "project": true, | ||
// "tsconfigRootDir": "__dirname" | ||
// }, | ||
"root": true, | ||
"rules": { | ||
// eslint rules | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
// playwright rules | ||
"playwright/expect-expect": "off", | ||
"playwright/no-skipped-test": "off", | ||
"playwright/no-conditional-in-test": "off", | ||
"playwright/no-standalone-expect": "off", | ||
"playwright/no-conditional-expect": "off", | ||
// custom rules | ||
// "no-restricted-syntax": [ | ||
// "error", | ||
// { | ||
// "selector": "CallExpression[callee.property.name='only']", | ||
// "message": "test.only is not allowed." | ||
// }, | ||
// ], | ||
}, | ||
} |
Oops, something went wrong.