Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
- 'pos-module-chat/**'
common-styling:
- 'pos-module-common-styling/**'
payments-stripe:
- 'pos-module-payments-stripe/**'

- name: Set matrix for changed modules
id: set-matrix
Expand All @@ -65,6 +67,12 @@ jobs:
"path": "pos-module-common-styling",
"deploy-script": "pos-cli data clean --include-schema --auto-confirm\npos-cli deploy",
"test-commands": "npm run pw-tests"
},
"payments-stripe": {
"module": "payments-stripe",
"path": "pos-module-payments-stripe",
"deploy-script": "mkdir -p tests/post_import/modules\ncp -r ../pos-module-core/modules/core tests/post_import/modules/\ncp -r ../pos-module-payments/modules/payments tests/post_import/modules/\ncp -r modules/payments_stripe tests/post_import/modules/\n./tests/data/seed/seed.sh",
"test-commands": "npm run pw-tests"
}
}
EOF
Expand Down Expand Up @@ -93,6 +101,7 @@ jobs:
MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }}
NPM_CONFIG_CACHE: ${{ github.workspace }}/.npm
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
STRIPE_SK_KEY: ${{ secrets.STRIPE_SK_KEY }}
HTML_ATTACHMENTS_BASE_URL: ${{ vars.HTML_ATTACHMENTS_BASE_URL }}
TEST_REPORT_MPKIT_URL: ${{ vars.TEST_REPORT_MPKIT_URL }}
TEST_REPORT_MPKIT_TOKEN: ${{ secrets.TEST_REPORT_MPKIT_TOKEN }}
Expand Down
93 changes: 93 additions & 0 deletions pos-module-payments-stripe/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pos-module-payments-stripe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"pw-tests": "playwright test tests --project=smoke-tests"
},
"devDependencies": {
"@playwright/test": "^1.58.2",
"@types/node": "^22.0.0"
}
}
43 changes: 43 additions & 0 deletions pos-module-payments-stripe/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineConfig, devices } from '@playwright/test';
import process from 'process';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 3 : 3,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
['list'],
['html', { outputFolder: 'playwright-report', open: 'never' }],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.MPKIT_URL,

screenshot: { mode: 'only-on-failure', fullPage: true },

viewport: null,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'retain-on-failure',
},

/* Configure projects for major browsers */
projects: [
{
name: 'smoke-tests',
testMatch: /.*\.spec\.ts/,
use: { ...devices['Desktop Chrome'] },
},
],
});
217 changes: 217 additions & 0 deletions pos-module-payments-stripe/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# E2E Tests for pos-module-payments-stripe

This directory contains end-to-end tests for the Stripe payments module using Playwright.

## Overview

The test suite verifies the Stripe Checkout integration, including:
- Payment page rendering
- Checkout session creation
- Webhook handling (success, expiration, failures)
- Error scenarios (invalid transactions, missing API keys)
- URL parameter preservation
- Multiple payment attempts

## Prerequisites

1. **Node.js and npm** installed
2. **Playwright** installed via `npm install`
3. **MPKIT_URL** environment variable set to your platformOS instance
4. **pos-cli** configured with environment access

## Test Setup

### Local Development Setup

```bash
# From the pos-module-payments-stripe directory

# 1. Install dependencies
npm install

# 2. Deploy test application to your development environment
pos-cli deploy <env>

# 3. Set environment variable
export MPKIT_URL=https://your-instance.staging.oregon.platform-os.com

# 4. Run tests
npm run pw-tests
```

### What Gets Deployed

The test setup deploys:
- **Test pages**: `/test-stripe-payment`, `/test-stripe-payment-post`, `/test-stripe-webhook`
- **Module dependencies**: core, payments, payments_stripe
- **Test configuration**: `tests/post_import/app/config.yml`

Files in `tests/post_import/` are deployed to create the test environment.

## Running Tests

### Run all tests
```bash
npm run pw-tests
```

### Run specific test file
```bash
npx playwright test tests/stripe-payment-page-load.spec.ts
```

### Run tests in headed mode (see browser)
```bash
npx playwright test --headed
```

### Run tests with UI mode
```bash
npx playwright test --ui
```

### Debug a test
```bash
npx playwright test --debug tests/stripe-webhook-success.spec.ts
```

## Test Structure

### Core Flow Tests (Priority 1)
- **seed.spec.ts**: Initial page load for warming up
- **stripe-payment-page-load.spec.ts**: Verifies payment page renders correctly
- **stripe-checkout-session-create.spec.ts**: Tests checkout session creation and Stripe redirect
- **stripe-webhook-success.spec.ts**: Tests successful payment webhook handling
- **stripe-webhook-expired.spec.ts**: Tests expired session webhook handling

### Error Scenario Tests (Priority 2)
- **stripe-invalid-transaction.spec.ts**: Tests handling of invalid transaction IDs
- **stripe-missing-api-key.spec.ts**: Tests graceful failure without Stripe API key

### Additional Coverage Tests (Priority 3)
- **stripe-url-parameters.spec.ts**: Verifies URL parameter preservation
- **stripe-multiple-attempts.spec.ts**: Tests multiple payment attempts

## Test Environment Limitations

### What We Can Test
- ✅ Transaction creation
- ✅ Checkout session URL generation
- ✅ Webhook handler logic (via simulation)
- ✅ Transaction status updates
- ✅ Success/failure redirects
- ✅ Error handling

### What We Cannot Test
- ❌ Actual Stripe checkout UI (external, hosted by Stripe)
- ❌ Real payment processing (requires test Stripe account)
- ❌ Webhook signature validation (requires Stripe webhook secret)

## Test Pages

### /test-stripe-payment (GET)
Displays a payment form with:
- Transaction details (amount, currency, gateway)
- "Start Payment" button
- Success/failure messages (based on query params)

### /test-stripe-payment-post (POST)
Handles form submission:
- Creates a transaction via payments module
- Generates Stripe checkout session
- Redirects to Stripe or returns error

### /test-stripe-webhook (POST)
Webhook simulator for testing:
- Accepts: `event_type`, `transaction_id`, `payment_status`
- Simulates Stripe webhook payload
- Calls transaction completion logic
- Returns success/error response

## CI Integration

Tests run automatically on GitHub Actions when:
- Pull requests are opened/updated
- Code is pushed to main branch
- Manual workflow dispatch

The workflow:
1. Deploys test application to staging environment
2. Runs all E2E tests
3. Generates HTML report
4. Uploads test results as artifacts

## Viewing Test Results

### Locally
After running tests, view the HTML report:
```bash
npx playwright show-report playwright-report
```

### CI
Test reports are available as workflow artifacts in GitHub Actions.

## Test Configuration

Configuration is in `playwright.config.ts`:
- **Base URL**: From `MPKIT_URL` environment variable
- **Browser**: Desktop Chrome
- **Retries**: 2 on CI, 0 locally
- **Workers**: 3 parallel workers
- **Screenshots**: Only on failure
- **Traces**: Retained on failure

## Troubleshooting

### Tests fail with "Cannot find module"
```bash
npm install
```

### Tests fail with "baseURL not set"
```bash
export MPKIT_URL=https://your-instance.staging.oregon.platform-os.com
```

### Tests fail with 404 errors
Deploy the test application:
```bash
pos-cli deploy <env>
```

### Checkout fails with API key error
This is expected in test environments without valid Stripe API keys. The tests are designed to handle this gracefully and verify error handling.

## Writing New Tests

1. Create a new `.spec.ts` file in `tests/`
2. Import Playwright test utilities: `import { test, expect } from '@playwright/test';`
3. Use `test.describe()` for grouping related tests
4. Use `test.step()` for logical test steps
5. Follow existing patterns for consistency

Example:
```typescript
import { test, expect } from '@playwright/test';

test.describe('My Test Suite', () => {
test('should do something', async ({ page }) => {
await test.step('First step', async () => {
await page.goto('/test-stripe-payment');
// assertions here
});
});
});
```

## Clean Up

After testing, you can clean up the deployed test files by removing the `tests/post_import/` deployment or by redeploying without test files.

## Support

For issues or questions:
- Check [Playwright documentation](https://playwright.dev)
- Check [platformOS documentation](https://documentation.platformos.com)
- Open an issue in the repository
Loading
Loading