Skip to content

Commit 0d6e18d

Browse files
author
MrJnrman
committed
fix failing tests
1 parent 8250664 commit 0d6e18d

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
lines changed

tests/payments-test-packages/CODE_CHANGES.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,42 @@ find ./bootstrap -type f -exec sed -i 's|/qit/bootstrap|./bootstrap|g' {} +
4848

4949
---
5050

51-
## 2. QIT Helpers Import Changes
51+
## 2. Bootstrap Test User Creation
52+
53+
**Why**: Tests expect specific users (from `config/users.json`) to exist. Your bootstrap must create them with matching credentials.
54+
55+
### bootstrap/setup.sh
56+
57+
Add user creation commands:
58+
59+
```bash
60+
# Create test users matching config/users.json
61+
wp user create customer [email protected] \
62+
--role=customer \
63+
--user_pass=password \
64+
--first_name="Jane" \
65+
--last_name="Smith" \
66+
--quiet 2>/dev/null || wp user update customer --user_pass=password --quiet
67+
68+
wp user create subscriptions-customer [email protected] \
69+
--role=customer \
70+
--user_pass=password \
71+
--quiet 2>/dev/null || wp user update subscriptions-customer --user_pass=password --quiet
72+
73+
wp user create editor [email protected] \
74+
--role=editor \
75+
--user_pass=password \
76+
--quiet 2>/dev/null || wp user update editor --user_pass=password --quiet
77+
```
78+
79+
**Important**:
80+
- Usernames and passwords must match `config/users.json`
81+
- The `|| wp user update` fallback handles cases where the user already exists
82+
- Without these users, authentication will fail in tests
83+
84+
---
85+
86+
## 3. QIT Helpers Import Changes
5287

5388
**Why**: Legacy tests used global `/qitHelpers` module. Test packages use local `@qit/helpers` package.
5489

@@ -78,7 +113,7 @@ find . -name "*.ts" -o -name "*.js" | xargs sed -i "s|from '/qitHelpers'|from '@
78113

79114
---
80115

81-
## 3. JSON Import Changes
116+
## 4. JSON Import Changes
82117

83118
**Why**: ES modules require import attributes for JSON files.
84119

@@ -121,7 +156,7 @@ grep -r "from.*\.json" . --include="*.ts" --include="*.js"
121156

122157
---
123158

124-
## 4. `__dirname` Shim for ES Modules
159+
## 5. `__dirname` Shim for ES Modules
125160

126161
**Why**: ES modules don't provide `__dirname` global like CommonJS does.
127162

@@ -163,7 +198,7 @@ grep -r "__dirname" . --include="*.ts" --include="*.js"
163198

164199
---
165200

166-
## 5. Required Dependencies
201+
## 6. Required Dependencies
167202

168203
**Why**: ES modules need Node.js type definitions, and QIT requires Allure reports.
169204

@@ -195,7 +230,7 @@ grep -r "__dirname" . --include="*.ts" --include="*.js"
195230

196231
---
197232

198-
## 6. RestAPI Import
233+
## 7. RestAPI Import
199234

200235
**Why**: `RestAPI` class needs to be imported if used in helper functions.
201236

@@ -235,7 +270,7 @@ export const getShopper = async (
235270

236271
---
237272

238-
## 7. Playwright Reporter Configuration
273+
## 8. Playwright Reporter Configuration
239274

240275
**Why**: QIT requires specific reporters to be configured for test results and Allure reports.
241276

@@ -284,7 +319,7 @@ export default defineConfig({
284319

285320
---
286321

287-
## 8. Test Package Manifest - Allure Directory
322+
## 9. Test Package Manifest - Allure Directory
288323

289324
**Why**: QIT needs to know where to find Allure results to upload them with test reports.
290325

@@ -318,6 +353,7 @@ Add `allure-dir` to the `results` section:
318353
When migrating tests to test packages, check for these code changes:
319354

320355
- [ ] Replace `/qit/bootstrap/` with `./bootstrap/` in all bootstrap scripts
356+
- [ ] Create test users in bootstrap matching `config/users.json` (customer, editor, etc.)
321357
- [ ] Replace `/qitHelpers` with `@qit/helpers` in all test files
322358
- [ ] Add `with { type: 'json' }` to JSON imports
323359
- [ ] Use default imports for JSON files

tests/payments-test-packages/GETTING_STARTED.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,23 @@ cp /path/to/my-plugin/tests/qit/e2e/bootstrap/*.sh ./bootstrap/
101101
cp /path/to/my-plugin/tests/qit/e2e/bootstrap/*.php ./bootstrap/
102102
```
103103

104-
**IMPORTANT**: Old tests used absolute paths (`/qit/bootstrap/`). These need to change to relative paths (`./bootstrap/`):
104+
**IMPORTANT**: Two changes are needed in bootstrap scripts:
105105

106-
```bash
107-
# Find files with old paths
108-
grep -r "/qit/bootstrap" ./bootstrap/
106+
1. **Fix paths** - Replace `/qit/bootstrap/` with `./bootstrap/`
109107

110-
# Replace with relative paths (macOS)
111-
find ./bootstrap -type f -exec sed -i '' 's|/qit/bootstrap|./bootstrap|g' {} +
108+
2. **Create correct test users** - Your bootstrap must create users matching `config/users.json`:
112109

113-
# Or on Linux
114-
find ./bootstrap -type f -exec sed -i 's|/qit/bootstrap|./bootstrap|g' {} +
110+
```bash
111+
# In bootstrap/setup.sh, create users with these exact credentials:
112+
wp user create customer [email protected] \
113+
--role=customer --user_pass=password --quiet
115114

116-
# Verify the change worked (should return nothing)
117-
grep -r "/qit/bootstrap" ./bootstrap/
115+
wp user create editor [email protected] \
116+
--role=editor --user_pass=password --quiet
118117
```
119118

119+
See [CODE_CHANGES.md](./CODE_CHANGES.md#1-bootstrap-path-changes) for details.
120+
120121
---
121122

122123
### Step 4: Add QIT Helpers

tests/payments-test-packages/bootstrap/setup.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,32 @@ wp theme activate storefront
9696

9797

9898

99-
# Create a test customer
100-
wp user create testcustomer [email protected] \
99+
# Create test users that match config/users.json
100+
# Customer user (required for shopper tests)
101+
wp user create customer [email protected] \
101102
--role=customer \
102-
--user_pass=testpass123 \
103-
--first_name="Test" \
103+
--user_pass=password \
104+
--first_name="Jane" \
105+
--last_name="Smith" \
106+
--quiet 2>/dev/null || wp user update customer --user_pass=password --quiet
107+
108+
# Subscriptions customer user (required for subscription tests)
109+
wp user create subscriptions-customer [email protected] \
110+
--role=customer \
111+
--user_pass=password \
112+
--first_name="Sub" \
104113
--last_name="Customer" \
105-
--quiet
114+
--quiet 2>/dev/null || wp user update subscriptions-customer --user_pass=password --quiet
115+
116+
# Editor user (required for editor tests)
117+
wp user create editor [email protected] \
118+
--role=editor \
119+
--user_pass=password \
120+
--first_name="Ed" \
121+
--last_name="Itor" \
122+
--quiet 2>/dev/null || wp user update editor --user_pass=password --quiet
123+
124+
echo "✅ Test users created (customer, subscriptions-customer, editor)"
106125

107126
echo "Setting up WooPayments configuration..."
108127

0 commit comments

Comments
 (0)