Skip to content

Commit 81a6619

Browse files
authored
Merge pull request #311 from objectstack-ai/copilot/fix-build-and-test
2 parents 2108890 + 50bc8ea commit 81a6619

11 files changed

Lines changed: 63 additions & 47 deletions

File tree

examples/msw-object-form/src/__tests__/Dashboard.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('Dashboard MSW Integration', () => {
111111
const driver = getDriver();
112112

113113
// Get actual data from server
114-
const contacts = await driver!.find('contact', {});
114+
const contacts = await driver!.find('contact', { object: 'contact' }) as any[];
115115
const activeContacts = contacts.filter(c => c.is_active);
116116

117117
const schema: DashboardSchema = {

examples/msw-object-form/src/__tests__/MSWServer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('MSW Server Integration', () => {
2222
expect(driver).toBeDefined();
2323

2424
// Check that initial data was loaded
25-
const contacts = await driver!.find('contact', {});
25+
const contacts = await driver!.find('contact', { object: 'contact' });
2626
expect(contacts).toHaveLength(3);
2727
expect(contacts[0].name).toBe('John Doe');
2828
});
@@ -35,7 +35,7 @@ describe('MSW Server Integration', () => {
3535
email: 'test@example.com',
3636
is_active: true,
3737
priority: 5
38-
});
38+
}) as any;
3939

4040
expect(newContact.name).toBe('Test User');
4141
expect(newContact.email).toBe('test@example.com');

examples/msw-object-form/src/__tests__/ObjectForm.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('ObjectForm with MSW Integration', () => {
3636
// Clean up created contacts after each test
3737
const driver = getDriver();
3838
if (driver) {
39-
const contacts = await driver.find('contact', {});
39+
const contacts = await driver.find('contact', { object: 'contact' });
4040
for (const contact of contacts) {
4141
if (contact.id && !['1', '2', '3'].includes(contact.id)) {
4242
await driver.delete('contact', contact.id);
@@ -260,7 +260,6 @@ describe('ObjectForm with MSW Integration', () => {
260260
});
261261

262262
it('should handle update errors gracefully', async () => {
263-
const user = userEvent.setup();
264263
const onError = vi.fn();
265264

266265
render(
@@ -461,9 +460,9 @@ describe('ObjectForm with MSW Integration', () => {
461460
const createdId = createdContact.id;
462461

463462
// Verify data is persisted by fetching it
464-
const result = await client.data.findById('contact', createdId);
465-
expect(result.value.name).toBe('Persist Test');
466-
expect(result.value.email).toBe('persist@example.com');
463+
const result = await client.data.get('contact', createdId);
464+
expect(result.name).toBe('Persist Test');
465+
expect(result.email).toBe('persist@example.com');
467466
});
468467
});
469468
});

examples/msw-object-form/src/__tests__/ObjectFormUnit.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class MockDataSource implements DataSource {
2626
}
2727
};
2828

29-
async getObjectSchema(objectName: string): Promise<any> {
29+
async getObjectSchema(_objectName: string): Promise<any> {
3030
return this.mockObject;
3131
}
3232

33-
async findOne(objectName: string, id: string): Promise<any> {
33+
async findOne(_objectName: string, id: string): Promise<any> {
3434
return {
3535
id,
3636
name: 'John Doe',
@@ -43,20 +43,21 @@ class MockDataSource implements DataSource {
4343
};
4444
}
4545

46-
async create(objectName: string, data: any): Promise<any> {
46+
async create(_objectName: string, data: any): Promise<any> {
4747
return { ...data, id: 'new-id' };
4848
}
4949

50-
async update(objectName: string, id: string, data: any): Promise<any> {
50+
async update(_objectName: string, id: string, data: any): Promise<any> {
5151
return { ...data, id };
5252
}
5353

54-
async delete(objectName: string, id: string): Promise<void> {
54+
async delete(_objectName: string, _id: string): Promise<boolean> {
5555
// Mock delete
56+
return true;
5657
}
5758

58-
async find(objectName: string, options?: any): Promise<any[]> {
59-
return [];
59+
async find(_objectName: string, _options?: any): Promise<{ data: any[] }> {
60+
return { data: [] };
6061
}
6162
}
6263

examples/msw-object-form/src/__tests__/ObjectGrid.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66

77
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
88
import { render, screen, waitFor } from '@testing-library/react';
9-
import userEvent from '@testing-library/user-event';
109
import '@testing-library/jest-dom';
10+
import { ObjectStackClient } from '@objectstack/client';
1111
import { ObjectGrid } from '@object-ui/plugin-grid';
1212
import { startMockServer, stopMockServer } from '../mocks/server';
1313
import { ObjectStackDataSource } from '../dataSource';
1414

1515
describe('ObjectGrid MSW Integration', () => {
16+
let client: ObjectStackClient;
1617
let dataSource: ObjectStackDataSource;
1718

1819
beforeAll(async () => {
1920
await startMockServer();
20-
dataSource = new ObjectStackDataSource();
21+
client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' });
22+
await client.connect();
23+
dataSource = new ObjectStackDataSource(client);
2124
});
2225

2326
afterAll(() => {
@@ -194,7 +197,7 @@ describe('ObjectGrid MSW Integration', () => {
194197

195198
describe('Data Loading', () => {
196199
it('should show loading state initially', async () => {
197-
const { container } = render(
200+
render(
198201
<ObjectGrid
199202
schema={{
200203
type: 'object-grid',

examples/msw-object-form/src/__tests__/ServerDefinitions.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66

77
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
8-
import { render, screen, waitFor } from '@testing-library/react';
8+
import { render, screen } from '@testing-library/react';
99
import '@testing-library/jest-dom';
1010
import { SchemaRenderer } from '@object-ui/react';
11-
import type { AppSchema, PageSchema } from '@object-ui/types';
11+
import type { AppSchema } from '@object-ui/types';
1212
import { startMockServer, stopMockServer } from '../mocks/server';
1313

1414
describe('Server-Driven Definitions', () => {
@@ -332,7 +332,7 @@ describe('Server-Driven Definitions', () => {
332332
};
333333

334334
expect(dynamicSchema.children[1].objectName).toBe('contact');
335-
expect(dynamicSchema.children[1].data.provider).toBe('object');
335+
expect(dynamicSchema.children[1].data?.provider).toBe('object');
336336
});
337337

338338
it('should support conditional rendering based on server data', () => {

examples/msw-object-form/src/dataSource.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,50 @@
44
* Adapter that connects ObjectForm to ObjectStack Client
55
*/
66

7-
import type { DataSource } from '@object-ui/types';
7+
import type { DataSource, QueryResult } from '@object-ui/types';
88
import type { ObjectStackClient } from '@objectstack/client';
99

1010
export class ObjectStackDataSource implements DataSource {
1111
constructor(private client: ObjectStackClient) {}
1212

1313
async getObjectSchema(objectName: string): Promise<any> {
1414
// Fetch object metadata from ObjectStack
15-
const metadata = await this.client.metadata.getObject(objectName);
15+
const metadata = await this.client.meta.getObject(objectName);
1616
return metadata;
1717
}
1818

1919
async findOne(objectName: string, id: string): Promise<any> {
20-
const result = await this.client.data.findById(objectName, id);
21-
return result.value;
20+
const result = await this.client.data.get(objectName, id);
21+
return result;
2222
}
2323

2424
async create(objectName: string, data: any): Promise<any> {
2525
const result = await this.client.data.create(objectName, data);
26-
return result.value;
26+
return result;
2727
}
2828

2929
async update(objectName: string, id: string, data: any): Promise<any> {
3030
const result = await this.client.data.update(objectName, id, data);
31-
return result.value;
31+
return result;
3232
}
3333

34-
async delete(objectName: string, id: string): Promise<void> {
35-
await this.client.data.delete(objectName, id);
34+
async delete(objectName: string, id: string): Promise<boolean> {
35+
const result = await this.client.data.delete(objectName, id);
36+
return result.success;
3637
}
3738

38-
async find(objectName: string, options?: any): Promise<any[]> {
39-
const result = await this.client.data.find(objectName, options);
40-
return result.value;
39+
async find(objectName: string, options?: any): Promise<QueryResult<any>> {
40+
const result: any = await this.client.data.find(objectName, options || {});
41+
42+
// Handle array response
43+
if (Array.isArray(result)) {
44+
return { data: result };
45+
}
46+
47+
// Handle ObjectStack response format
48+
return {
49+
data: result.value || result,
50+
total: result.count,
51+
};
4152
}
4253
}

examples/msw-object-form/src/mocks/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ObjectKernel, DriverPlugin, AppPlugin } from '@objectstack/runtime';
99
import { ObjectQLPlugin } from '@objectstack/objectql';
1010
import { InMemoryDriver } from '@objectstack/driver-memory';
1111
import { MSWPlugin } from '@objectstack/plugin-msw';
12+
// @ts-expect-error - Config file not in src directory
1213
import appConfig from '../../objectstack.config';
1314

1415
let kernel: ObjectKernel | null = null;

examples/msw-object-form/src/mocks/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ObjectQLPlugin } from '@objectstack/objectql';
1010
import { InMemoryDriver } from '@objectstack/driver-memory';
1111
import { setupServer } from 'msw/node';
1212
import { http, HttpResponse } from 'msw';
13+
// @ts-expect-error - Config file not in src directory
1314
import appConfig from '../../objectstack.config';
1415

1516
let kernel: ObjectKernel | null = null;
@@ -84,7 +85,7 @@ export function getDriver(): InMemoryDriver | null {
8485
* Create MSW request handlers for ObjectStack API
8586
*/
8687
function createHandlers(baseUrl: string, kernel: ObjectKernel) {
87-
const protocol = kernel.getService('protocol');
88+
const protocol = kernel.getService('protocol') as any;
8889

8990
return [
9091
// Discovery endpoint

packages/core/src/query/__tests__/window-functions.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('QueryASTBuilder - Window Functions', () => {
2828
orderBy: [{ field: 'salary', direction: 'desc' as const }],
2929
};
3030

31-
// @ts-ignore - testing private method
31+
// @ts-expect-error - testing private method
3232
const result: WindowNode = builder.buildWindow(config);
3333

3434
expect(result).toMatchObject({
@@ -61,7 +61,7 @@ describe('QueryASTBuilder - Window Functions', () => {
6161
],
6262
};
6363

64-
// @ts-ignore
64+
// @ts-expect-error - testing private method
6565
const result: WindowNode = builder.buildWindow(config);
6666

6767
expect(result).toMatchObject({
@@ -85,7 +85,7 @@ describe('QueryASTBuilder - Window Functions', () => {
8585
defaultValue: 0,
8686
};
8787

88-
// @ts-ignore
88+
// @ts-expect-error - testing private method
8989
const result: WindowNode = builder.buildWindow(config);
9090

9191
expect(result).toMatchObject({
@@ -116,7 +116,7 @@ describe('QueryASTBuilder - Window Functions', () => {
116116
offset: 1,
117117
};
118118

119-
// @ts-ignore
119+
// @ts-expect-error - testing private method
120120
const result: WindowNode = builder.buildWindow(config);
121121

122122
expect(result).toMatchObject({
@@ -140,7 +140,7 @@ describe('QueryASTBuilder - Window Functions', () => {
140140
},
141141
};
142142

143-
// @ts-ignore
143+
// @ts-expect-error - testing private method
144144
const result: WindowNode = builder.buildWindow(sumConfig);
145145

146146
expect(result).toMatchObject({
@@ -170,7 +170,7 @@ describe('QueryASTBuilder - Window Functions', () => {
170170
orderBy: [{ field: 'created_at', direction: 'asc' as const }],
171171
};
172172

173-
// @ts-ignore
173+
// @ts-expect-error - testing private method
174174
const result: WindowNode = builder.buildWindow(config);
175175

176176
expect(result).toMatchObject({
@@ -189,7 +189,7 @@ describe('QueryASTBuilder - Window Functions', () => {
189189
orderBy: [{ field: 'updated_at', direction: 'desc' as const }],
190190
};
191191

192-
// @ts-ignore
192+
// @ts-expect-error - testing private method
193193
const result: WindowNode = builder.buildWindow(config);
194194

195195
expect(result).toMatchObject({
@@ -206,7 +206,7 @@ describe('QueryASTBuilder - Window Functions', () => {
206206
orderBy: [{ field: 'created_at', direction: 'asc' as const }],
207207
};
208208

209-
// @ts-ignore
209+
// @ts-expect-error - testing private method
210210
const result: WindowNode = builder.buildWindow(config);
211211

212212
expect(result.partitionBy).toBeUndefined();
@@ -226,7 +226,7 @@ describe('QueryASTBuilder - Window Functions', () => {
226226
},
227227
};
228228

229-
// @ts-ignore
229+
// @ts-expect-error - testing private method
230230
const result: WindowNode = builder.buildWindow(config);
231231

232232
expect(result.frame).toEqual({
@@ -244,7 +244,7 @@ describe('QueryASTBuilder - Window Functions', () => {
244244
orderBy: [{ field: 'score', direction: 'desc' as const }],
245245
};
246246

247-
// @ts-ignore
247+
// @ts-expect-error - testing private method
248248
const result: WindowNode = builder.buildWindow(config);
249249

250250
expect(result).toMatchObject({
@@ -262,7 +262,7 @@ describe('QueryASTBuilder - Window Functions', () => {
262262
orderBy: [{ field: 'exam_score', direction: 'desc' as const }],
263263
};
264264

265-
// @ts-ignore
265+
// @ts-expect-error - testing private method
266266
const result: WindowNode = builder.buildWindow(config);
267267

268268
expect(result).toMatchObject({

0 commit comments

Comments
 (0)