Skip to content

Commit 62c44e7

Browse files
committed
feat: add debug logging for task fetching and data verification in TaskList and browser mocks
1 parent 1506349 commit 62c44e7

3 files changed

Lines changed: 49 additions & 20 deletions

File tree

examples/app-react-crud/src/components/TaskList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export function TaskList({ client, onEdit, refreshTrigger }: TaskListProps) {
4343

4444
// Client-side sort fallback (since InMemoryDriver has limited sort support)
4545
// Sort by Priority (Ascending) -> Created At (Descending)
46+
console.log('[TaskList] Received tasks:', fetchedTasks);
47+
4648
fetchedTasks.sort((a, b) => {
4749
if (a.priority !== b.priority) {
4850
return a.priority - b.priority;

examples/app-react-crud/src/mocks/browser.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export async function startMockServer() {
2222
// Handle CommonJS/ESM interop for config loading
2323
const appConfig = (todoConfig as any).default || todoConfig;
2424
console.log('[MSW] Loaded Config:', appConfig);
25+
26+
// DEBUG: Verify Data Existence
27+
const manifestData = appConfig.data || (appConfig.manifest && appConfig.manifest.data);
28+
if (manifestData && Array.isArray(manifestData)) {
29+
console.log(`[MSW] DATA DETECTED: Found ${manifestData.length} datasets in config.`);
30+
manifestData.forEach((d: any) => console.log(`[MSW] Dataset: object=${d.object}, records=${d.records?.length}`));
31+
} else {
32+
console.error('[MSW] CRITICAL: No initial data found in loaded config!', appConfig);
33+
}
2534

2635
const driver = new InMemoryDriver();
2736

@@ -120,6 +129,19 @@ export async function startMockServer() {
120129

121130
await kernel.bootstrap();
122131

132+
// DEBUG: Verify Seeding Result
133+
const ql = kernel.context?.getService<any>('objectql');
134+
if (ql) {
135+
setTimeout(async () => {
136+
try {
137+
const tasks = await ql.find('todo_task');
138+
console.log(`[MSW] POST-BOOTSTRAP VERIFICATION: Found ${tasks?.length} tasks in DB.`, tasks);
139+
} catch(e) {
140+
console.error('[MSW] Verification failed', e);
141+
}
142+
}, 500); // Small delay to ensure async seeding is definitely done (though bootstrap should cover it)
143+
}
144+
123145
// --- PROTOCOL SERVICE MOCK ---
124146
// Overwrite protocol service because the default one might be empty/broken in this env
125147
if (kernel.services instanceof Map) {
@@ -137,27 +159,10 @@ export async function startMockServer() {
137159
}
138160

139161
// Initialize default data from manifest if available
162+
// Data seeding is handled by AppPlugin automatically
140163
const manifest = appConfig.manifest;
141164
console.log('[MSW] Checking manifest for data...', manifest);
142165

143-
if (manifest && Array.isArray(manifest.data)) {
144-
console.log(`[MSW] Found ${manifest.data.length} datasets.`);
145-
for (const dataset of manifest.data) {
146-
if (dataset.object && Array.isArray(dataset.records)) {
147-
for (const record of dataset.records) {
148-
// Check if record already exists to avoid duplicates on hot reload?
149-
// Since it's in-memory and we create new kernel/driver on refresh...
150-
// But 'kernel' variable is module-scoped singleton.
151-
// On HMR replacement, this module might re-execute.
152-
// If 'kernel' is not null, we return early (line 18).
153-
// So data loading happens only once per session. Good.
154-
await driver.create(dataset.object, record);
155-
}
156-
console.log(`[MSW] Loaded ${dataset.records.length} records for ${dataset.object}`);
157-
}
158-
}
159-
}
160-
161166
return kernel;
162167
}
163168

examples/app-react-crud/test/api.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ describe('App React CRUD Integration Tests', () => {
2121
kernel = new ObjectKernel();
2222
const driver = new InMemoryDriver();
2323

24+
// Handle CommonJS/ESM interop for config loading
25+
const appConfig = (todoConfig as any).default || todoConfig;
26+
2427
await kernel.use(new ObjectQLPlugin());
2528
await kernel.use(new DriverPlugin(driver, 'memory'));
26-
await kernel.use(new AppPlugin(todoConfig));
29+
await kernel.use(new AppPlugin(appConfig));
2730

2831
// 2. Initialize MSW Plugin to generate handlers
2932
const mswPlugin = new MSWPlugin({
@@ -83,6 +86,7 @@ describe('App React CRUD Integration Tests', () => {
8386
}
8487

8588
// HttpDispatcher expects { data, count } for query/list
89+
console.log(`[BrokerShim-Test] find/query(${params.object}) -> count: ${all.length}`);
8690
return { data: all, count: all.length };
8791
}
8892
}
@@ -96,9 +100,13 @@ describe('App React CRUD Integration Tests', () => {
96100
objs = SchemaRegistry.getAllObjects();
97101
}
98102

99-
console.log('DEBUG: metadata.objects returned count:', objs.length, 'names:', objs.map((o: any) => o.name));
103+
// console.log('DEBUG: metadata.objects returned count:', objs.length, 'names:', objs.map((o: any) => o.name));
100104
return objs;
101105
}
106+
if (method === 'getObject') {
107+
// Try Registry first for speed/correctness
108+
return SchemaRegistry.getObject(params.objectName) || (ql ? ql.getObject(params.objectName) : null);
109+
}
102110
if (method === 'getObject') {
103111
// Try Registry first for speed/correctness
104112
return SchemaRegistry.getObject(params.objectName) || ql.getObject(params.objectName);
@@ -130,6 +138,8 @@ describe('App React CRUD Integration Tests', () => {
130138
}
131139

132140

141+
142+
133143
// 3. Set up MSW Node Server with handlers from the plugin
134144
const handlers = mswPlugin.getHandlers();
135145
console.log('DEBUG: MSW Handlers registered:', handlers.map(h => h.info.header));
@@ -178,6 +188,18 @@ describe('App React CRUD Integration Tests', () => {
178188
expect(taskObject?.label).toBe('Todo Task');
179189
});
180190

191+
it('should have initial seeded data', async () => {
192+
// Find tasks without filter
193+
const response = await client.data.find('todo_task', {});
194+
// Response format: { success: true, data: [...], meta: { count: N } }
195+
const list = response.data;
196+
expect(list).toBeDefined();
197+
expect(Array.isArray(list)).toBe(true);
198+
// Expect at least 5 seeded records
199+
expect(list.length).toBeGreaterThanOrEqual(1);
200+
console.log(`[Test] Initial data check: Found ${list.length} records.`);
201+
});
202+
181203
it('should check if ui protocol getUiView is available', async () => {
182204
// Use client.meta.getView
183205
// This might fail if protocol service doesn't support getUiView in this test env

0 commit comments

Comments
 (0)