Skip to content

Commit 6b01250

Browse files
authored
Merge pull request #45 from objectstack-ai/copilot/fix-github-action-error
2 parents 4f54b5f + f8320a6 commit 6b01250

File tree

1 file changed

+199
-18
lines changed

1 file changed

+199
-18
lines changed

packages/spec/src/system/plugin.test.ts

Lines changed: 199 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,77 @@ import {
1111
describe('PluginContextSchema', () => {
1212
it('should accept valid plugin context', () => {
1313
const context: PluginContextData = {
14-
ql: {},
15-
os: {},
16-
logger: {},
14+
ql: {
15+
object: () => ({}),
16+
query: async () => ({})
17+
},
18+
os: {
19+
getCurrentUser: async () => ({ id: 'test-user' }),
20+
getConfig: async () => 'test-config'
21+
},
22+
logger: {
23+
debug: () => {},
24+
info: () => {},
25+
warn: () => {},
26+
error: () => {}
27+
},
28+
storage: {
29+
get: async () => null,
30+
set: async () => {},
31+
delete: async () => {}
32+
},
33+
i18n: {
34+
t: () => '',
35+
getLocale: () => 'en'
36+
},
1737
metadata: {},
1838
events: {},
39+
app: {
40+
router: {
41+
get: () => {},
42+
post: () => {},
43+
use: () => {}
44+
}
45+
}
1946
};
2047

2148
expect(() => PluginContextSchema.parse(context)).not.toThrow();
2249
});
2350

2451
it('should accept context with all required properties', () => {
2552
const completeContext = {
26-
ql: {},
27-
os: {},
28-
logger: {},
53+
ql: {
54+
object: () => ({}),
55+
query: async () => ({})
56+
},
57+
os: {
58+
getCurrentUser: async () => ({ id: 'test-user' }),
59+
getConfig: async () => 'test-config'
60+
},
61+
logger: {
62+
debug: () => {},
63+
info: () => {},
64+
warn: () => {},
65+
error: () => {}
66+
},
67+
storage: {
68+
get: async () => null,
69+
set: async () => {},
70+
delete: async () => {}
71+
},
72+
i18n: {
73+
t: () => '',
74+
getLocale: () => 'en'
75+
},
2976
metadata: {},
3077
events: {},
78+
app: {
79+
router: {
80+
get: () => {},
81+
post: () => {},
82+
use: () => {}
83+
}
84+
}
3185
};
3286

3387
const result = PluginContextSchema.safeParse(completeContext);
@@ -41,15 +95,27 @@ describe('PluginContextSchema', () => {
4195
find: async () => [],
4296
create: async (data: any) => data,
4397
}),
98+
query: async (soql: string) => ({ records: [] })
4499
},
45100
os: {
46101
getCurrentUser: async () => ({ id: 'user123' }),
47102
getConfig: async (key: string) => 'value',
48103
},
49104
logger: {
105+
debug: (message: string) => console.log(message),
50106
info: (message: string) => console.log(message),
107+
warn: (message: string) => console.warn(message),
51108
error: (message: string, error?: any) => console.error(message, error),
52109
},
110+
storage: {
111+
get: async (key: string) => null,
112+
set: async (key: string, value: any) => {},
113+
delete: async (key: string) => {}
114+
},
115+
i18n: {
116+
t: (key: string, params?: any) => key,
117+
getLocale: () => 'en-US'
118+
},
53119
metadata: {
54120
getObject: async (name: string) => ({}),
55121
getFields: async (object: string) => [],
@@ -58,6 +124,13 @@ describe('PluginContextSchema', () => {
58124
on: (event: string, handler: Function) => {},
59125
emit: (event: string, data?: any) => {},
60126
},
127+
app: {
128+
router: {
129+
get: (path: string, handler: Function) => {},
130+
post: (path: string, handler: Function) => {},
131+
use: (pathOrHandler: string | Function, handler?: Function) => {}
132+
}
133+
}
61134
};
62135

63136
expect(() => PluginContextSchema.parse(context)).not.toThrow();
@@ -216,11 +289,38 @@ describe('Plugin Lifecycle Scenarios', () => {
216289
// Simulate installation
217290
if (parsed.onInstall) {
218291
await parsed.onInstall({
219-
ql: { object: () => ({ syncSchema: async () => {} }) },
220-
os: {},
221-
logger: { info: () => {}, error: () => {} },
292+
ql: {
293+
object: () => ({ syncSchema: async () => {} }),
294+
query: async () => ({})
295+
},
296+
os: {
297+
getCurrentUser: async () => ({ id: 'test-user' }),
298+
getConfig: async () => 'test-config'
299+
},
300+
logger: {
301+
debug: () => {},
302+
info: () => {},
303+
warn: () => {},
304+
error: () => {}
305+
},
306+
storage: {
307+
get: async () => null,
308+
set: async () => {},
309+
delete: async () => {}
310+
},
311+
i18n: {
312+
t: () => '',
313+
getLocale: () => 'en'
314+
},
222315
metadata: {},
223316
events: {},
317+
app: {
318+
router: {
319+
get: () => {},
320+
post: () => {},
321+
use: () => {}
322+
}
323+
}
224324
} as any);
225325
}
226326

@@ -246,11 +346,38 @@ describe('Plugin Lifecycle Scenarios', () => {
246346
const parsed = PluginSchema.parse(plugin);
247347

248348
const mockContext = {
249-
ql: {},
250-
os: {},
251-
logger: { info: () => {}, error: () => {} },
349+
ql: {
350+
object: () => ({}),
351+
query: async () => ({})
352+
},
353+
os: {
354+
getCurrentUser: async () => ({ id: 'test-user' }),
355+
getConfig: async () => 'test-config'
356+
},
357+
logger: {
358+
debug: () => {},
359+
info: () => {},
360+
warn: () => {},
361+
error: () => {}
362+
},
363+
storage: {
364+
get: async () => null,
365+
set: async () => {},
366+
delete: async () => {}
367+
},
368+
i18n: {
369+
t: () => '',
370+
getLocale: () => 'en'
371+
},
252372
metadata: {},
253373
events: {},
374+
app: {
375+
router: {
376+
get: () => {},
377+
post: () => {},
378+
use: () => {}
379+
}
380+
}
254381
} as any;
255382

256383
// Enable
@@ -286,11 +413,38 @@ describe('Plugin Lifecycle Scenarios', () => {
286413
if (parsed.onUpgrade) {
287414
await parsed.onUpgrade(
288415
{
289-
ql: {},
290-
os: {},
291-
logger: { info: () => {}, error: () => {} },
416+
ql: {
417+
object: () => ({}),
418+
query: async () => ({})
419+
},
420+
os: {
421+
getCurrentUser: async () => ({ id: 'test-user' }),
422+
getConfig: async () => 'test-config'
423+
},
424+
logger: {
425+
debug: () => {},
426+
info: () => {},
427+
warn: () => {},
428+
error: () => {}
429+
},
430+
storage: {
431+
get: async () => null,
432+
set: async () => {},
433+
delete: async () => {}
434+
},
435+
i18n: {
436+
t: () => '',
437+
getLocale: () => 'en'
438+
},
292439
metadata: {},
293440
events: {},
441+
app: {
442+
router: {
443+
get: () => {},
444+
post: () => {},
445+
use: () => {}
446+
}
447+
}
294448
} as any,
295449
'1.0.0',
296450
'2.0.0'
@@ -318,11 +472,38 @@ describe('Plugin Lifecycle Scenarios', () => {
318472

319473
if (parsed.onUninstall) {
320474
await parsed.onUninstall({
321-
ql: { object: () => ({ dropTable: async () => {} }) },
322-
os: {},
323-
logger: { info: () => {}, error: () => {} },
475+
ql: {
476+
object: () => ({ dropTable: async () => {} }),
477+
query: async () => ({})
478+
},
479+
os: {
480+
getCurrentUser: async () => ({ id: 'test-user' }),
481+
getConfig: async () => 'test-config'
482+
},
483+
logger: {
484+
debug: () => {},
485+
info: () => {},
486+
warn: () => {},
487+
error: () => {}
488+
},
489+
storage: {
490+
get: async () => null,
491+
set: async () => {},
492+
delete: async () => {}
493+
},
494+
i18n: {
495+
t: () => '',
496+
getLocale: () => 'en'
497+
},
324498
metadata: {},
325499
events: {},
500+
app: {
501+
router: {
502+
get: () => {},
503+
post: () => {},
504+
use: () => {}
505+
}
506+
}
326507
} as any);
327508
}
328509

0 commit comments

Comments
 (0)