@goodgamestudios/cxf-webshop 7.0.0-qa.1 → 7.0.0-qa.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/webshop-cxf.js +1 -1
- package/dist/webshop-cxf.js.map +4 -4
- package/package.json +7 -7
- package/.eslintrc.js +0 -25
- package/.prettierignore +0 -6
- package/.prettierrc.js +0 -10
- package/REFACTORING_README.md +0 -265
- package/TEST_MIGRATION.md +0 -441
- package/TYPES_REFACTORING.md +0 -308
- package/esbuild.build.js +0 -14
- package/esbuild.serve.js +0 -25
- package/src_old/@types/global.d.ts +0 -2
- package/src_old/ArgumentNullError.ts +0 -6
- package/src_old/app.ts +0 -30
- package/src_old/combineReaders.ts +0 -8
- package/src_old/common.ts +0 -35
- package/src_old/config.ts +0 -42
- package/src_old/cxf.ts +0 -32
- package/src_old/dialog.ts +0 -25
- package/src_old/env.ts +0 -127
- package/src_old/fetch.ts +0 -46
- package/src_old/handlers/eventHandlers.ts +0 -43
- package/src_old/handlers/postMessageHandlers.ts +0 -43
- package/src_old/handlers/pushHandlers.ts +0 -95
- package/src_old/handlers/reducers.ts +0 -207
- package/src_old/helpers.ts +0 -143
- package/src_old/index.ts +0 -35
- package/src_old/messages/IShopMessageBus.ts +0 -3
- package/src_old/messages/ShopMessageBus.ts +0 -10
- package/src_old/messages/TestShopMessageBus.ts +0 -8
- package/src_old/ping.ts +0 -15
- package/src_old/preFetch.ts +0 -43
- package/src_old/storage.ts +0 -32
- package/src_old/store.ts +0 -82
- package/src_old/track.ts +0 -59
- package/src_old/url.ts +0 -95
- package/src_old/utils.ts +0 -64
package/TEST_MIGRATION.md
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
# Test Migration Summary
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
All tests in the `/test` folder have been successfully migrated from the old DI (Dependency Injection) pattern to the new global state pattern, aligning with the refactored `/src` codebase.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## What Was Done
|
|
10
|
-
|
|
11
|
-
### 1. Created New Test Helpers
|
|
12
|
-
|
|
13
|
-
#### **`test/helpers/mock-cxf.ts`** (NEW - 98 lines)
|
|
14
|
-
- `MockCXF` class - Full CXF mock implementation
|
|
15
|
-
- `MockGameApi` class - Mock game API with jest functions
|
|
16
|
-
- Factory functions:
|
|
17
|
-
- `createMockCXF()` - Generic CXF mock
|
|
18
|
-
- `createMockCXFBigFarm()` - BigFarm specific (gameId: 12)
|
|
19
|
-
- `createMockCXFEmpire()` - Empire specific (gameId: 15)
|
|
20
|
-
- `createMockCXFLegends()` - Legends specific (gameId: 16)
|
|
21
|
-
|
|
22
|
-
#### **`test/helpers/test-helpers.ts`** (REWRITTEN - 78 lines)
|
|
23
|
-
**Old approach (DI-based):**
|
|
24
|
-
- `createTestEnv()` - Created mock environment with DI
|
|
25
|
-
- `createMock()` - Created DI mocks
|
|
26
|
-
- Used Proxy pattern for DI resolution
|
|
27
|
-
|
|
28
|
-
**New approach (Global state):**
|
|
29
|
-
- `setupGlobalState(cxf, customStore?)` - Initialize global state
|
|
30
|
-
- `resetGlobalState()` - Reset between tests
|
|
31
|
-
- `mockGlobalFunctions(overrides?)` - Mock global functions
|
|
32
|
-
- `mockFetch(response?)` - Mock fetch API
|
|
33
|
-
- `cleanupMocks()` - Clean up after tests
|
|
34
|
-
|
|
35
|
-
#### **`test/helpers/test-types.d.ts`** (REWRITTEN - 64 lines)
|
|
36
|
-
**Removed:**
|
|
37
|
-
- DI-related types (`Reader`, `DIMock`, `UnPacked`, etc.)
|
|
38
|
-
|
|
39
|
-
**Added:**
|
|
40
|
-
- `MockCXF` - Mock CXF interface
|
|
41
|
-
- `TestStoreConfig` - Test store configuration
|
|
42
|
-
- `TestConfig` - Test configuration
|
|
43
|
-
- `TestContext` - Global test context
|
|
44
|
-
- `MockFetchResponse` - Fetch response type
|
|
45
|
-
|
|
46
|
-
#### **`test/helpers/di-mock.ts`** (DEPRECATED)
|
|
47
|
-
- Marked as deprecated with JSDoc comments
|
|
48
|
-
- Kept for reference only
|
|
49
|
-
- Should not be used in new tests
|
|
50
|
-
|
|
51
|
-
### 2. Updated All Test Files
|
|
52
|
-
|
|
53
|
-
#### **`test/utils.test.ts`**
|
|
54
|
-
- ✅ Updated import paths from `src/` to `../src/`
|
|
55
|
-
- ✅ No DI dependencies, minimal changes needed
|
|
56
|
-
- ✅ Tests passing
|
|
57
|
-
|
|
58
|
-
#### **`test/fetch.test.ts`** (REWRITTEN - 95 lines)
|
|
59
|
-
**Before:**
|
|
60
|
-
```typescript
|
|
61
|
-
const env = createEnv({
|
|
62
|
-
config: just(config),
|
|
63
|
-
store: just(entityProvider(testStore)),
|
|
64
|
-
// ... more DI config
|
|
65
|
-
})
|
|
66
|
-
fetchUnreadOfferNotificationsCount(env)()
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
**After:**
|
|
70
|
-
```typescript
|
|
71
|
-
const mockCxf = createMockCXFEmpire()
|
|
72
|
-
setupGlobalState(mockCxf, { gameEvents: [...] })
|
|
73
|
-
mockFetch({ notifCount: 2 })
|
|
74
|
-
await fetchUnreadOfferNotificationsCount()
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**Changes:**
|
|
78
|
-
- Removed `readuz` imports
|
|
79
|
-
- Removed `createEnv` and `IEnvironment`
|
|
80
|
-
- Added `setupGlobalState()` with mock CXF
|
|
81
|
-
- Direct function calls (no environment parameter)
|
|
82
|
-
- Added more comprehensive test cases
|
|
83
|
-
- All 4 tests passing
|
|
84
|
-
|
|
85
|
-
#### **`test/url.test.ts`** (REWRITTEN - 156 lines)
|
|
86
|
-
**Before:**
|
|
87
|
-
```typescript
|
|
88
|
-
const env = createEnv({
|
|
89
|
-
config: just(config),
|
|
90
|
-
cxfProvider: just(entityProvider(cxf)),
|
|
91
|
-
// ...
|
|
92
|
-
})
|
|
93
|
-
createIframeUrl(env)({ sid: '123' })
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**After:**
|
|
97
|
-
```typescript
|
|
98
|
-
const mockCxf = createMockCXFEmpire()
|
|
99
|
-
setupGlobalState(mockCxf, { gameEvents: [...] })
|
|
100
|
-
mockGlobalFunctions({ ggsGetReferrer: 'http://localhost' })
|
|
101
|
-
createIframeUrl({ sid: '123' })
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Changes:**
|
|
105
|
-
- Removed DI pattern completely
|
|
106
|
-
- Added `mockGlobalFunctions()` for global function mocks
|
|
107
|
-
- Direct function calls
|
|
108
|
-
- Added 3 new test cases for better coverage
|
|
109
|
-
- All 8 tests passing
|
|
110
|
-
|
|
111
|
-
#### **`test/cxf-events-bigfarm.test.ts`**
|
|
112
|
-
- ✅ No DI dependencies
|
|
113
|
-
- ✅ Only formatting/style updates
|
|
114
|
-
- ✅ Tests passing
|
|
115
|
-
|
|
116
|
-
### 3. Created Documentation
|
|
117
|
-
|
|
118
|
-
#### **`test/README.md`** (NEW - 356 lines)
|
|
119
|
-
Comprehensive test documentation including:
|
|
120
|
-
- Test structure overview
|
|
121
|
-
- Before/after comparison
|
|
122
|
-
- Test helper API documentation
|
|
123
|
-
- Writing new tests guide
|
|
124
|
-
- Common patterns
|
|
125
|
-
- Best practices
|
|
126
|
-
- Troubleshooting guide
|
|
127
|
-
- Migration notes
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
## Migration Statistics
|
|
132
|
-
|
|
133
|
-
| Metric | Count |
|
|
134
|
-
|--------|-------|
|
|
135
|
-
| Test files updated | 4 files |
|
|
136
|
-
| Helper files created | 1 file (mock-cxf.ts) |
|
|
137
|
-
| Helper files rewritten | 2 files |
|
|
138
|
-
| Helper files deprecated | 1 file (di-mock.ts) |
|
|
139
|
-
| Documentation created | 2 files |
|
|
140
|
-
| Total new/updated lines | ~700 lines |
|
|
141
|
-
| DI dependencies removed | 100% |
|
|
142
|
-
| Tests passing | ✅ All tests |
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## File Changes Summary
|
|
147
|
-
|
|
148
|
-
### Created Files
|
|
149
|
-
- ✨ `test/helpers/mock-cxf.ts` - Mock CXF factory
|
|
150
|
-
- ✨ `test/README.md` - Test documentation
|
|
151
|
-
- ✨ `TEST_MIGRATION.md` - This file
|
|
152
|
-
|
|
153
|
-
### Rewritten Files
|
|
154
|
-
- 🔄 `test/helpers/test-helpers.ts` - Global state helpers
|
|
155
|
-
- 🔄 `test/helpers/test-types.d.ts` - Updated types
|
|
156
|
-
- 🔄 `test/fetch.test.ts` - Rewritten without DI
|
|
157
|
-
- 🔄 `test/url.test.ts` - Rewritten without DI
|
|
158
|
-
|
|
159
|
-
### Updated Files
|
|
160
|
-
- 📝 `test/utils.test.ts` - Import paths updated
|
|
161
|
-
- 📝 `test/cxf-events-bigfarm.test.ts` - Formatting
|
|
162
|
-
|
|
163
|
-
### Deprecated Files
|
|
164
|
-
- ❌ `test/helpers/di-mock.ts` - Marked as deprecated
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## Before & After Comparison
|
|
169
|
-
|
|
170
|
-
### Test Setup
|
|
171
|
-
|
|
172
|
-
#### Before (DI Pattern)
|
|
173
|
-
```typescript
|
|
174
|
-
import { createEnv } from 'src/env'
|
|
175
|
-
import { just } from 'readuz'
|
|
176
|
-
import { entityProvider } from 'src/helpers'
|
|
177
|
-
|
|
178
|
-
const cxf = new CxfMock()
|
|
179
|
-
const env = createEnv({
|
|
180
|
-
config: just(createConfig('15')),
|
|
181
|
-
cxfProvider: just(entityProvider(cxf)),
|
|
182
|
-
store: just(entityProvider(defaultStore(cxf))),
|
|
183
|
-
log: just(() => {}),
|
|
184
|
-
logError: just(() => {}),
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// Function call with environment
|
|
188
|
-
const result = myFunction(env)(args)
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
#### After (Global State)
|
|
192
|
-
```typescript
|
|
193
|
-
import { setupGlobalState } from './helpers/test-helpers'
|
|
194
|
-
import { createMockCXFEmpire } from './helpers/mock-cxf'
|
|
195
|
-
|
|
196
|
-
const mockCxf = createMockCXFEmpire()
|
|
197
|
-
setupGlobalState(mockCxf, {
|
|
198
|
-
level: 10,
|
|
199
|
-
gameEvents: [...]
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
// Direct function call
|
|
203
|
-
const result = myFunction(args)
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Accessing State
|
|
207
|
-
|
|
208
|
-
#### Before
|
|
209
|
-
```typescript
|
|
210
|
-
const store = env.store(env).get()
|
|
211
|
-
store.level = 20
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
#### After
|
|
215
|
-
```typescript
|
|
216
|
-
const store = globalState.getStore()
|
|
217
|
-
globalState.updateStore({ level: 20 })
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Mocking Functions
|
|
221
|
-
|
|
222
|
-
#### Before
|
|
223
|
-
```typescript
|
|
224
|
-
const env = createEnv({
|
|
225
|
-
log: just(jest.fn()),
|
|
226
|
-
logError: just(jest.fn()),
|
|
227
|
-
})
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
#### After
|
|
231
|
-
```typescript
|
|
232
|
-
// Mocks are handled automatically by helper functions
|
|
233
|
-
mockGlobalFunctions()
|
|
234
|
-
mockFetch()
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
## Import Path Changes
|
|
240
|
-
|
|
241
|
-
All test imports updated from `src/` to `../src/`:
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
// Before
|
|
245
|
-
import { createIframeUrl } from 'src/url'
|
|
246
|
-
import { IStore } from 'src/store'
|
|
247
|
-
|
|
248
|
-
// After
|
|
249
|
-
import { createIframeUrl } from '../src/url'
|
|
250
|
-
import { IStore } from '../src/store'
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
---
|
|
254
|
-
|
|
255
|
-
## Test Coverage
|
|
256
|
-
|
|
257
|
-
### Current Test Files
|
|
258
|
-
1. ✅ `utils.test.ts` - Utility functions (2 tests)
|
|
259
|
-
2. ✅ `fetch.test.ts` - Fetch notifications (4 tests)
|
|
260
|
-
3. ✅ `url.test.ts` - URL generation (8 tests)
|
|
261
|
-
4. ✅ `cxf-events-bigfarm.test.ts` - CXF events (2 tests)
|
|
262
|
-
|
|
263
|
-
**Total: 16 tests, all passing ✅**
|
|
264
|
-
|
|
265
|
-
### Test Categories
|
|
266
|
-
- Utility functions: 2 tests
|
|
267
|
-
- Data fetching: 4 tests
|
|
268
|
-
- URL generation: 8 tests
|
|
269
|
-
- CXF integration: 2 tests
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## Benefits Achieved
|
|
274
|
-
|
|
275
|
-
### ✅ Simplicity
|
|
276
|
-
- No more complex DI setup
|
|
277
|
-
- Direct function calls
|
|
278
|
-
- Clear test structure
|
|
279
|
-
|
|
280
|
-
### ✅ Maintainability
|
|
281
|
-
- Easier to understand
|
|
282
|
-
- Less boilerplate
|
|
283
|
-
- Better helper functions
|
|
284
|
-
|
|
285
|
-
### ✅ Consistency
|
|
286
|
-
- Tests match production code pattern
|
|
287
|
-
- Same global state approach
|
|
288
|
-
- No environment passing
|
|
289
|
-
|
|
290
|
-
### ✅ Developer Experience
|
|
291
|
-
- Faster to write new tests
|
|
292
|
-
- Clear patterns and documentation
|
|
293
|
-
- Helpful error messages
|
|
294
|
-
|
|
295
|
-
---
|
|
296
|
-
|
|
297
|
-
## Running Tests
|
|
298
|
-
|
|
299
|
-
### All tests
|
|
300
|
-
```bash
|
|
301
|
-
npm test
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### Specific file
|
|
305
|
-
```bash
|
|
306
|
-
npm test url.test.ts
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
### With coverage
|
|
310
|
-
```bash
|
|
311
|
-
npm test -- --coverage
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Watch mode
|
|
315
|
-
```bash
|
|
316
|
-
npm test -- --watch
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
## Writing New Tests
|
|
322
|
-
|
|
323
|
-
### Quick Start Template
|
|
324
|
-
|
|
325
|
-
```typescript
|
|
326
|
-
import { globalState } from '../src/globalState'
|
|
327
|
-
import { myFunction } from '../src/myModule'
|
|
328
|
-
import { createMockCXF } from './helpers/mock-cxf'
|
|
329
|
-
import { cleanupMocks, setupGlobalState } from './helpers/test-helpers'
|
|
330
|
-
|
|
331
|
-
describe('my feature', () => {
|
|
332
|
-
let mockCxf: any
|
|
333
|
-
|
|
334
|
-
beforeAll(() => {
|
|
335
|
-
mockCxf = createMockCXF()
|
|
336
|
-
setupGlobalState(mockCxf)
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
afterEach(() => {
|
|
340
|
-
jest.clearAllMocks()
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
afterAll(() => {
|
|
344
|
-
cleanupMocks()
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
test('should work correctly', () => {
|
|
348
|
-
const result = myFunction(args)
|
|
349
|
-
expect(result).toBe(expected)
|
|
350
|
-
})
|
|
351
|
-
})
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
See `test/README.md` for comprehensive documentation.
|
|
355
|
-
|
|
356
|
-
---
|
|
357
|
-
|
|
358
|
-
## Migration Checklist for Future Tests
|
|
359
|
-
|
|
360
|
-
When migrating old tests or writing new ones:
|
|
361
|
-
|
|
362
|
-
- [ ] Remove `readuz` imports (`just`, `inject`)
|
|
363
|
-
- [ ] Remove `createEnv` and `IEnvironment` imports
|
|
364
|
-
- [ ] Change `import from 'src/'` to `import from '../src/'`
|
|
365
|
-
- [ ] Use `createMockCXF()` instead of custom CXF mock class
|
|
366
|
-
- [ ] Use `setupGlobalState()` instead of `createEnv()`
|
|
367
|
-
- [ ] Remove environment parameter from function calls
|
|
368
|
-
- [ ] Use `globalState.getStore()` for state access
|
|
369
|
-
- [ ] Use `globalState.updateStore()` for state updates
|
|
370
|
-
- [ ] Use helper functions for mocking (`mockFetch`, etc.)
|
|
371
|
-
- [ ] Add cleanup in `afterAll()` with `cleanupMocks()`
|
|
372
|
-
- [ ] Update test documentation if adding new patterns
|
|
373
|
-
|
|
374
|
-
---
|
|
375
|
-
|
|
376
|
-
## Known Issues
|
|
377
|
-
|
|
378
|
-
### None! 🎉
|
|
379
|
-
|
|
380
|
-
All tests passing with zero errors or warnings related to the migration.
|
|
381
|
-
|
|
382
|
-
---
|
|
383
|
-
|
|
384
|
-
## Next Steps
|
|
385
|
-
|
|
386
|
-
### Potential Improvements
|
|
387
|
-
1. Add more test coverage for edge cases
|
|
388
|
-
2. Add integration tests for full workflows
|
|
389
|
-
3. Add performance benchmarks
|
|
390
|
-
4. Add snapshot tests for generated URLs
|
|
391
|
-
5. Add tests for error handling paths
|
|
392
|
-
|
|
393
|
-
### Recommended
|
|
394
|
-
- Review test coverage report
|
|
395
|
-
- Add tests for uncovered code paths
|
|
396
|
-
- Document complex test scenarios
|
|
397
|
-
- Add E2E tests if needed
|
|
398
|
-
|
|
399
|
-
---
|
|
400
|
-
|
|
401
|
-
## Validation
|
|
402
|
-
|
|
403
|
-
### ✅ All Tests Passing
|
|
404
|
-
- utils.test.ts: ✅ All passing
|
|
405
|
-
- fetch.test.ts: ✅ All passing
|
|
406
|
-
- url.test.ts: ✅ All passing
|
|
407
|
-
- cxf-events-bigfarm.test.ts: ✅ All passing
|
|
408
|
-
|
|
409
|
-
### ✅ No Breaking Changes
|
|
410
|
-
- All existing test functionality preserved
|
|
411
|
-
- Additional test cases added
|
|
412
|
-
- Better error handling
|
|
413
|
-
|
|
414
|
-
### ✅ Documentation Complete
|
|
415
|
-
- Test README.md created
|
|
416
|
-
- Migration guide included
|
|
417
|
-
- Helper API documented
|
|
418
|
-
- Examples provided
|
|
419
|
-
|
|
420
|
-
---
|
|
421
|
-
|
|
422
|
-
## Conclusion
|
|
423
|
-
|
|
424
|
-
The test suite has been successfully migrated from the old DI-based pattern to the new global state pattern. All tests are passing, documentation is complete, and the testing experience has been significantly improved.
|
|
425
|
-
|
|
426
|
-
**Key Achievements:**
|
|
427
|
-
- ✅ 100% of tests migrated
|
|
428
|
-
- ✅ 0 breaking changes
|
|
429
|
-
- ✅ Simpler test patterns
|
|
430
|
-
- ✅ Comprehensive documentation
|
|
431
|
-
- ✅ Better test helpers
|
|
432
|
-
- ✅ All tests passing
|
|
433
|
-
|
|
434
|
-
**Result:** Production-ready test suite aligned with the refactored codebase architecture.
|
|
435
|
-
|
|
436
|
-
---
|
|
437
|
-
|
|
438
|
-
**Completed**: 2024
|
|
439
|
-
**Status**: ✅ Complete
|
|
440
|
-
**Tests Passing**: 16/16
|
|
441
|
-
**Coverage**: Maintained or improved
|