Skip to content

Commit 30fa3ec

Browse files
authored
Merge pull request #430 from objectstack-ai/copilot/fix-login-page-display
2 parents 328c99b + f2e2482 commit 30fa3ec

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

packages/data-objectstack/src/connection.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,44 @@ describe('Batch Progress Events', () => {
9898
unsubscribe();
9999
});
100100
});
101+
102+
describe('getDiscovery', () => {
103+
it('should return discoveryInfo from the underlying client after connect', async () => {
104+
const mockDiscovery = {
105+
name: 'test-server',
106+
version: '1.0.0',
107+
services: {
108+
auth: { enabled: false, status: 'unavailable' },
109+
data: { enabled: true, status: 'available' },
110+
},
111+
};
112+
113+
const adapter = new ObjectStackAdapter({
114+
baseUrl: 'http://localhost:3000',
115+
autoReconnect: false,
116+
});
117+
118+
// Mock the underlying client's connect method and discoveryInfo property
119+
const client = adapter.getClient();
120+
vi.spyOn(client, 'connect').mockResolvedValue(mockDiscovery as any);
121+
// Simulate what connect() does: sets discoveryInfo
122+
(client as any).discoveryInfo = mockDiscovery;
123+
124+
const discovery = await adapter.getDiscovery();
125+
expect(discovery).toEqual(mockDiscovery);
126+
expect((discovery as any)?.services?.auth?.enabled).toBe(false);
127+
});
128+
129+
it('should return null when connection fails', async () => {
130+
const adapter = new ObjectStackAdapter({
131+
baseUrl: 'http://localhost:3000',
132+
autoReconnect: false,
133+
});
134+
135+
const client = adapter.getClient();
136+
vi.spyOn(client, 'connect').mockRejectedValue(new Error('Connection failed'));
137+
138+
const discovery = await adapter.getDiscovery();
139+
expect(discovery).toBeNull();
140+
});
141+
});

packages/data-objectstack/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
601601
// Access discovery data from the client
602602
// The ObjectStackClient caches discovery during connect()
603603
// This is an internal property, but documented for this use case
604-
// @ts-expect-error - Accessing internal discovery property
605-
return this.client.discovery || null;
604+
// @ts-expect-error - Accessing internal discoveryInfo property
605+
return this.client.discoveryInfo || null;
606606
} catch {
607607
return null;
608608
}

0 commit comments

Comments
 (0)