Skip to content

Commit 2f923ae

Browse files
committed
test(objectql): the stored-row read gate pins pass typed query options
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwurKjbb54r3yD6yJg
1 parent 7c48766 commit 2f923ae

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

‎packages/objectql/src/stored-metadata-type-read-gate.test.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,52 +113,52 @@ describe('[#27884] stored-row read gate on the stored-metadata tables', () => {
113113
await engine.init();
114114
for (const table of ['sys_metadata', 'sys_metadata_history']) {
115115
engine.registry.registerObject(tableOf(table));
116-
await engine.insert(table, { id: `${table}_ds`, type: 'datasource', name: 'ds_pin', metadata: datasourceBody }, { context: { isSystem: true } } as any);
117-
await engine.insert(table, { id: `${table}_cat`, type: 'external_catalog', name: 'ds_pin', metadata: '{}' }, { context: { isSystem: true } } as any);
118-
await engine.insert(table, { id: `${table}_view`, type: 'view', name: 'v_pin', metadata: viewBody }, { context: { isSystem: true } } as any);
116+
await engine.insert(table, { id: `${table}_ds`, type: 'datasource', name: 'ds_pin', metadata: datasourceBody }, { context: { isSystem: true } });
117+
await engine.insert(table, { id: `${table}_cat`, type: 'external_catalog', name: 'ds_pin', metadata: '{}' }, { context: { isSystem: true } });
118+
await engine.insert(table, { id: `${table}_view`, type: 'view', name: 'v_pin', metadata: viewBody }, { context: { isSystem: true } });
119119
}
120120
vi.spyOn((engine as any).logger, 'debug').mockImplementation(() => undefined);
121121
});
122122

123123
it('a datasource administrator reads the row whole: connection configuration and credentialsRef', async () => {
124-
const rows = await engine.find('sys_metadata', { where: { type: 'datasource' }, context: ADMIN } as any);
124+
const rows = await engine.find('sys_metadata', { where: { type: 'datasource' }, context: ADMIN });
125125
expect(rows).toHaveLength(1);
126126
const body = JSON.parse(rows[0].metadata);
127127
expect(body.external.credentialsRef).toBe(REF);
128128
expect(body.config).toMatchObject({ host: HOST, port: 5432, database: 'pin_db', username: 'pin_user' });
129-
const one = await engine.findOne('sys_metadata', { where: { id: 'sys_metadata_ds' }, context: ADMIN } as any);
129+
const one = await engine.findOne('sys_metadata', { where: { id: 'sys_metadata_ds' }, context: ADMIN });
130130
expect(one?.type).toBe('datasource');
131-
expect(await engine.count('sys_metadata', { context: ADMIN } as any)).toBe(3);
131+
expect(await engine.count('sys_metadata', { context: ADMIN })).toBe(3);
132132
});
133133

134134
for (const [label, caller] of [['the built-in organization administrator', ORG_ADMIN], ['a plain reader', READER]] as const) {
135135
it(`${label} is served no datasource-family row on sys_metadata (find, findOne, count, aggregate)`, async () => {
136-
const listed = await engine.find('sys_metadata', { context: caller } as any);
136+
const listed = await engine.find('sys_metadata', { context: caller });
137137
expect(listed.map((r: any) => r.type).sort()).toEqual(['view']);
138138
expect(JSON.stringify(listed)).not.toContain(REF);
139139
expect(JSON.stringify(listed)).not.toContain(HOST);
140140

141141
// Asked for by type: nothing, not a refusal that names the row.
142-
expect(await engine.find('sys_metadata', { where: { type: 'datasource' }, context: caller } as any)).toEqual([]);
142+
expect(await engine.find('sys_metadata', { where: { type: 'datasource' }, context: caller })).toEqual([]);
143143
// A get of the row's id answers as a get of a row that does not exist.
144-
expect(await engine.findOne('sys_metadata', { where: { id: 'sys_metadata_ds' }, context: caller } as any)).toBeNull();
145-
expect(await engine.count('sys_metadata', { where: { type: 'datasource' }, context: caller } as any)).toBe(0);
146-
expect(await engine.count('sys_metadata', { context: caller } as any)).toBe(1);
147-
const agg: any = await engine.aggregate('sys_metadata', { where: { type: 'external_catalog' }, groupBy: ['type'], aggregations: [{ function: 'count', alias: 'n' }], context: caller } as any);
144+
expect(await engine.findOne('sys_metadata', { where: { id: 'sys_metadata_ds' }, context: caller })).toBeNull();
145+
expect(await engine.count('sys_metadata', { where: { type: 'datasource' }, context: caller })).toBe(0);
146+
expect(await engine.count('sys_metadata', { context: caller })).toBe(1);
147+
const agg: any = await engine.aggregate('sys_metadata', { where: { type: 'external_catalog' }, groupBy: ['type'], aggregations: [{ function: 'count', alias: 'n' }], context: caller });
148148
expect(JSON.stringify(agg)).toContain('"n":0');
149149
});
150150
}
151151

152152
it('the history table (the same document, versioned) is gated by the same row', async () => {
153-
const author = await engine.find('sys_metadata_history', { context: STUDIO_AUTHOR } as any);
153+
const author = await engine.find('sys_metadata_history', { context: STUDIO_AUTHOR });
154154
expect(author.map((r: any) => r.type)).toEqual(['view']);
155-
expect(await engine.findOne('sys_metadata_history', { where: { id: 'sys_metadata_history_ds' }, context: STUDIO_AUTHOR } as any)).toBeNull();
156-
const admin = await engine.find('sys_metadata_history', { context: ADMIN } as any);
155+
expect(await engine.findOne('sys_metadata_history', { where: { id: 'sys_metadata_history_ds' }, context: STUDIO_AUTHOR })).toBeNull();
156+
const admin = await engine.find('sys_metadata_history', { context: ADMIN });
157157
expect(admin.map((r: any) => r.type).sort()).toEqual(['datasource', 'external_catalog', 'view']);
158158
});
159159

160160
it('a system read is the platform\'s own and is not narrowed', async () => {
161-
const rows = await engine.find('sys_metadata', { context: { isSystem: true } } as any);
161+
const rows = await engine.find('sys_metadata', { context: { isSystem: true } });
162162
expect(rows).toHaveLength(3);
163163
});
164164

@@ -189,10 +189,10 @@ describe('[#27884] realtime events of a datasource-family row carry no body to a
189189
engine.setRealtimeService(realtime);
190190
vi.spyOn((engine as any).logger, 'debug').mockImplementation(() => undefined);
191191

192-
await engine.insert('sys_metadata', { id: 'e_ds', type: 'datasource', name: 'ds_pin', metadata: datasourceBody }, { context: { isSystem: true } } as any);
193-
await engine.update('sys_metadata', { id: 'e_ds', metadata: datasourceBody }, { context: { isSystem: true } } as any);
194-
await engine.insert('sys_metadata', { id: 'e_cat', type: 'external_catalog', name: 'ds_pin', metadata: '{"tables":[]}' }, { context: { isSystem: true } } as any);
195-
await engine.insert('sys_metadata', { id: 'e_view', type: 'view', name: 'v_pin', metadata: viewBody }, { context: { isSystem: true } } as any);
192+
await engine.insert('sys_metadata', { id: 'e_ds', type: 'datasource', name: 'ds_pin', metadata: datasourceBody }, { context: { isSystem: true } });
193+
await engine.update('sys_metadata', { id: 'e_ds', metadata: datasourceBody }, { context: { isSystem: true } });
194+
await engine.insert('sys_metadata', { id: 'e_cat', type: 'external_catalog', name: 'ds_pin', metadata: '{"tables":[]}' }, { context: { isSystem: true } });
195+
await engine.insert('sys_metadata', { id: 'e_view', type: 'view', name: 'v_pin', metadata: viewBody }, { context: { isSystem: true } });
196196

197197
expect(published).toHaveLength(4);
198198
for (const event of published.slice(0, 3)) {

0 commit comments

Comments
 (0)