@karpeleslab/klbfw 0.2.0 → 0.2.1
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/index.d.ts +81 -0
- package/package.json +8 -1
- package/CLAUDE.md +0 -50
- package/coverage/clover.xml +0 -835
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/cookies.js.html +0 -334
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fw-wrapper.js.html +0 -163
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/index.js.html +0 -196
- package/coverage/lcov-report/internal.js.html +0 -604
- package/coverage/lcov-report/klbfw/cookies.js.html +0 -490
- package/coverage/lcov-report/klbfw/fw-wrapper.js.html +0 -745
- package/coverage/lcov-report/klbfw/index.html +0 -206
- package/coverage/lcov-report/klbfw/index.js.html +0 -235
- package/coverage/lcov-report/klbfw/internal.js.html +0 -811
- package/coverage/lcov-report/klbfw/rest.js.html +0 -565
- package/coverage/lcov-report/klbfw/test/index.html +0 -116
- package/coverage/lcov-report/klbfw/test/setup.js.html +0 -1105
- package/coverage/lcov-report/klbfw/upload.js.html +0 -3487
- package/coverage/lcov-report/klbfw/util.js.html +0 -388
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/rest.js.html +0 -472
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/upload.js.html +0 -1789
- package/coverage/lcov-report/util.js.html +0 -313
- package/coverage/lcov.info +0 -1617
- package/test/README.md +0 -62
- package/test/api.test.js +0 -102
- package/test/cookies.test.js +0 -65
- package/test/integration.test.js +0 -481
- package/test/rest.test.js +0 -93
- package/test/setup.js +0 -341
- package/test/upload.test.js +0 -689
- package/test/util.test.js +0 -46
package/test/setup.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Mock fetch for Node environment
|
|
4
|
-
global.fetch = require('node-fetch');
|
|
5
|
-
|
|
6
|
-
// Mock browser APIs that might not exist in test environment
|
|
7
|
-
global.FormData = global.FormData || class FormData {};
|
|
8
|
-
|
|
9
|
-
// Create FW global object - this is always present in both browser and SSR
|
|
10
|
-
global.FW = {
|
|
11
|
-
Context: {
|
|
12
|
-
b: "master",
|
|
13
|
-
c: "USD",
|
|
14
|
-
l: "en-US",
|
|
15
|
-
g: "default"
|
|
16
|
-
},
|
|
17
|
-
GET: {},
|
|
18
|
-
Locale: "en-US",
|
|
19
|
-
Realm: {
|
|
20
|
-
Domain: "example.com",
|
|
21
|
-
Name: "example.com"
|
|
22
|
-
},
|
|
23
|
-
Registry: {
|
|
24
|
-
Currency_List: "USD",
|
|
25
|
-
Language__: "en-US",
|
|
26
|
-
System_Timezone: "UTC"
|
|
27
|
-
},
|
|
28
|
-
URL: {
|
|
29
|
-
full: "https://example.com/l/en-US/",
|
|
30
|
-
host: "example.com",
|
|
31
|
-
path: "/l/en-US/",
|
|
32
|
-
scheme: "https"
|
|
33
|
-
},
|
|
34
|
-
cookies: {
|
|
35
|
-
Locale: "en-US"
|
|
36
|
-
},
|
|
37
|
-
hostname: "example.com",
|
|
38
|
-
mode: "client", // default to client mode
|
|
39
|
-
path: "/",
|
|
40
|
-
prefix: "/l/en-US",
|
|
41
|
-
token: "test-csrf-token",
|
|
42
|
-
uuid: "00000000-0000-0000-0000-000000000000"
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Setup test modes
|
|
46
|
-
const setupSSRMode = () => {
|
|
47
|
-
// Configure SSR mode
|
|
48
|
-
FW.mode = "ssr";
|
|
49
|
-
|
|
50
|
-
// Add platform functions for SSR
|
|
51
|
-
global.__platformAsyncRest = jest.fn().mockImplementation((name, verb, params, context) => {
|
|
52
|
-
return Promise.resolve({
|
|
53
|
-
result: 'success',
|
|
54
|
-
data: { mock: 'data' }
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
global.__platformRest = jest.fn().mockImplementation((name, verb, params, context) => {
|
|
59
|
-
return {
|
|
60
|
-
result: 'success',
|
|
61
|
-
data: { mock: 'data' }
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
global.__platformSetCookie = jest.fn();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const setupClientMode = () => {
|
|
69
|
-
// Configure client mode
|
|
70
|
-
FW.mode = "client";
|
|
71
|
-
|
|
72
|
-
// Remove platform functions
|
|
73
|
-
if (global.__platformAsyncRest) delete global.__platformAsyncRest;
|
|
74
|
-
if (global.__platformRest) delete global.__platformRest;
|
|
75
|
-
if (global.__platformSetCookie) delete global.__platformSetCookie;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Helper to reset mocks between tests
|
|
79
|
-
const resetMocks = () => {
|
|
80
|
-
if (global.__platformAsyncRest) {
|
|
81
|
-
global.__platformAsyncRest.mockClear();
|
|
82
|
-
// Set up custom implementation for debug endpoints
|
|
83
|
-
global.__platformAsyncRest.mockImplementation((name, verb, params, context) => {
|
|
84
|
-
switch(name) {
|
|
85
|
-
case 'Misc/Debug:request':
|
|
86
|
-
return Promise.resolve({
|
|
87
|
-
result: 'success',
|
|
88
|
-
data: {
|
|
89
|
-
headers: { 'user-agent': 'Jest Test' },
|
|
90
|
-
ip: '127.0.0.1',
|
|
91
|
-
method: verb || 'GET',
|
|
92
|
-
path: '/api/Misc/Debug:request'
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
case 'Misc/Debug:params':
|
|
96
|
-
return Promise.resolve({
|
|
97
|
-
result: 'success',
|
|
98
|
-
data: params || { empty: true }
|
|
99
|
-
});
|
|
100
|
-
case 'Misc/Debug:fixedString':
|
|
101
|
-
return Promise.resolve({
|
|
102
|
-
result: 'success',
|
|
103
|
-
data: "fixed string"
|
|
104
|
-
});
|
|
105
|
-
case 'Misc/Debug:error':
|
|
106
|
-
return Promise.reject({
|
|
107
|
-
result: 'error',
|
|
108
|
-
error: 'This is an error response',
|
|
109
|
-
code: 'TEST_ERROR'
|
|
110
|
-
});
|
|
111
|
-
case 'Misc/Debug:testUpload':
|
|
112
|
-
return Promise.resolve({
|
|
113
|
-
result: 'success',
|
|
114
|
-
data: {
|
|
115
|
-
files: [
|
|
116
|
-
{
|
|
117
|
-
name: params?.name || 'test-file.jpg',
|
|
118
|
-
size: params?.size || 12345,
|
|
119
|
-
type: params?.type || 'image/jpeg'
|
|
120
|
-
}
|
|
121
|
-
]
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
default:
|
|
125
|
-
return Promise.resolve({
|
|
126
|
-
result: 'success',
|
|
127
|
-
data: { mock: 'data' }
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (global.__platformRest) {
|
|
134
|
-
global.__platformRest.mockClear();
|
|
135
|
-
// Set up custom implementation for debug endpoints
|
|
136
|
-
global.__platformRest.mockImplementation((name, verb, params, context) => {
|
|
137
|
-
switch(name) {
|
|
138
|
-
case 'Misc/Debug:request':
|
|
139
|
-
return {
|
|
140
|
-
result: 'success',
|
|
141
|
-
data: {
|
|
142
|
-
headers: { 'user-agent': 'Jest Test' },
|
|
143
|
-
ip: '127.0.0.1',
|
|
144
|
-
method: verb || 'GET',
|
|
145
|
-
path: '/api/Misc/Debug:request'
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
case 'Misc/Debug:params':
|
|
149
|
-
return {
|
|
150
|
-
result: 'success',
|
|
151
|
-
data: params || { empty: true }
|
|
152
|
-
};
|
|
153
|
-
case 'Misc/Debug:fixedString':
|
|
154
|
-
return {
|
|
155
|
-
result: 'success',
|
|
156
|
-
data: "fixed string"
|
|
157
|
-
};
|
|
158
|
-
case 'Misc/Debug:error':
|
|
159
|
-
throw {
|
|
160
|
-
result: 'error',
|
|
161
|
-
error: 'This is an error response',
|
|
162
|
-
code: 'TEST_ERROR'
|
|
163
|
-
};
|
|
164
|
-
case 'Misc/Debug:testUpload':
|
|
165
|
-
return {
|
|
166
|
-
result: 'success',
|
|
167
|
-
data: {
|
|
168
|
-
files: [
|
|
169
|
-
{
|
|
170
|
-
name: params?.name || 'test-file.jpg',
|
|
171
|
-
size: params?.size || 12345,
|
|
172
|
-
type: params?.type || 'image/jpeg'
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
default:
|
|
178
|
-
return {
|
|
179
|
-
result: 'success',
|
|
180
|
-
data: { mock: 'data' }
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (global.__platformSetCookie) {
|
|
187
|
-
global.__platformSetCookie.mockClear();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Reset fetch mock with custom implementation for debug endpoints
|
|
191
|
-
global.fetch = jest.fn().mockImplementation((url, options) => {
|
|
192
|
-
// Extract endpoint from URL
|
|
193
|
-
let endpoint = '';
|
|
194
|
-
|
|
195
|
-
// Try to extract endpoint name from URL
|
|
196
|
-
if (url.includes('Misc/Debug:request')) {
|
|
197
|
-
endpoint = 'Misc/Debug:request';
|
|
198
|
-
} else if (url.includes('Misc/Debug:params')) {
|
|
199
|
-
endpoint = 'Misc/Debug:params';
|
|
200
|
-
} else if (url.includes('Misc/Debug:fixedString')) {
|
|
201
|
-
endpoint = 'Misc/Debug:fixedString';
|
|
202
|
-
} else if (url.includes('Misc/Debug:error')) {
|
|
203
|
-
endpoint = 'Misc/Debug:error';
|
|
204
|
-
} else if (url.includes('Misc/Debug:testUpload')) {
|
|
205
|
-
endpoint = 'Misc/Debug:testUpload';
|
|
206
|
-
} else if (url.includes('Cloud/Aws/Bucket/Upload')) {
|
|
207
|
-
// Special case for upload
|
|
208
|
-
return Promise.resolve({
|
|
209
|
-
ok: true,
|
|
210
|
-
status: 200,
|
|
211
|
-
statusText: 'OK',
|
|
212
|
-
headers: {
|
|
213
|
-
get: (header) => header.toLowerCase() === 'content-type' ? 'application/json' : null
|
|
214
|
-
},
|
|
215
|
-
json: () => Promise.resolve({
|
|
216
|
-
result: 'success',
|
|
217
|
-
data: {
|
|
218
|
-
authorization: 'AWS4-HMAC-SHA256 test-auth'
|
|
219
|
-
}
|
|
220
|
-
}),
|
|
221
|
-
text: () => Promise.resolve('')
|
|
222
|
-
});
|
|
223
|
-
} else if (url.includes('example.com/upload')) {
|
|
224
|
-
// For upload file PUT
|
|
225
|
-
return Promise.resolve({
|
|
226
|
-
ok: true,
|
|
227
|
-
status: 200,
|
|
228
|
-
statusText: 'OK',
|
|
229
|
-
headers: {
|
|
230
|
-
get: (header) => null
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// For error endpoint, return error response
|
|
236
|
-
if (endpoint === 'Misc/Debug:error') {
|
|
237
|
-
return Promise.resolve({
|
|
238
|
-
ok: false,
|
|
239
|
-
status: 400,
|
|
240
|
-
statusText: 'Bad Request',
|
|
241
|
-
headers: {
|
|
242
|
-
get: (header) => header.toLowerCase() === 'content-type' ? 'application/json' : null
|
|
243
|
-
},
|
|
244
|
-
json: () => Promise.resolve({
|
|
245
|
-
result: 'error',
|
|
246
|
-
error: 'This is an error response',
|
|
247
|
-
code: 'TEST_ERROR'
|
|
248
|
-
})
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Extract params from request body
|
|
253
|
-
let params = {};
|
|
254
|
-
if (options && options.body) {
|
|
255
|
-
try {
|
|
256
|
-
if (typeof options.body === 'string') {
|
|
257
|
-
params = JSON.parse(options.body);
|
|
258
|
-
} else if (options.body instanceof FormData) {
|
|
259
|
-
params = {
|
|
260
|
-
name: 'test-file.jpg',
|
|
261
|
-
size: 12345,
|
|
262
|
-
type: 'image/jpeg',
|
|
263
|
-
isFormData: true
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
} catch (e) {
|
|
267
|
-
// Ignore parsing errors
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Return response based on endpoint
|
|
272
|
-
const responseData = (() => {
|
|
273
|
-
switch(endpoint) {
|
|
274
|
-
case 'Misc/Debug:request':
|
|
275
|
-
return {
|
|
276
|
-
result: 'success',
|
|
277
|
-
data: {
|
|
278
|
-
headers: { 'user-agent': 'Jest Test' },
|
|
279
|
-
ip: '127.0.0.1',
|
|
280
|
-
method: options?.method || 'GET',
|
|
281
|
-
path: '/api/Misc/Debug:request'
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
case 'Misc/Debug:params':
|
|
285
|
-
return {
|
|
286
|
-
result: 'success',
|
|
287
|
-
data: params || { empty: true }
|
|
288
|
-
};
|
|
289
|
-
case 'Misc/Debug:fixedString':
|
|
290
|
-
return {
|
|
291
|
-
result: 'success',
|
|
292
|
-
data: "fixed string"
|
|
293
|
-
};
|
|
294
|
-
case 'Misc/Debug:testUpload':
|
|
295
|
-
return {
|
|
296
|
-
result: 'success',
|
|
297
|
-
data: {
|
|
298
|
-
PUT: 'https://example.com/upload',
|
|
299
|
-
Complete: 'Misc/Debug:testUpload',
|
|
300
|
-
Blocksize: 5242880,
|
|
301
|
-
id: 'test-file-id',
|
|
302
|
-
name: 'test.jpg',
|
|
303
|
-
size: 12345,
|
|
304
|
-
type: 'image/jpeg'
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
default:
|
|
308
|
-
return {
|
|
309
|
-
result: 'success',
|
|
310
|
-
data: { mock: 'data' }
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
})();
|
|
314
|
-
|
|
315
|
-
return Promise.resolve({
|
|
316
|
-
ok: true,
|
|
317
|
-
status: 200,
|
|
318
|
-
statusText: 'OK',
|
|
319
|
-
headers: {
|
|
320
|
-
get: (header) => header.toLowerCase() === 'content-type' ? 'application/json' : null
|
|
321
|
-
},
|
|
322
|
-
json: () => Promise.resolve(responseData)
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
// Reset cookies
|
|
327
|
-
FW.cookies = {
|
|
328
|
-
Locale: "en-US"
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// Reset document.cookie if in browser environment
|
|
332
|
-
if (typeof document !== 'undefined') {
|
|
333
|
-
document.cookie = '';
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
module.exports = {
|
|
338
|
-
setupSSRMode,
|
|
339
|
-
setupClientMode,
|
|
340
|
-
resetMocks
|
|
341
|
-
};
|