|
| 1 | +import RpcAgent from '../src/agent'; |
| 2 | + |
| 3 | +function createAgent(): RpcAgent { |
| 4 | + return Object.create(RpcAgent.prototype) as RpcAgent; |
| 5 | +} |
| 6 | + |
| 7 | +function buildCollectionFixture(actionSchema: Record<string, unknown>) { |
| 8 | + return { |
| 9 | + name: 'Files', |
| 10 | + schema: { |
| 11 | + fields: {}, |
| 12 | + actions: { download: actionSchema }, |
| 13 | + aggregationCapabilities: { |
| 14 | + supportedDateOperations: new Set<string>(), |
| 15 | + supportGroups: false, |
| 16 | + }, |
| 17 | + countable: false, |
| 18 | + searchable: false, |
| 19 | + charts: [], |
| 20 | + segments: [], |
| 21 | + }, |
| 22 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 23 | + } as any; |
| 24 | +} |
| 25 | + |
| 26 | +describe('RpcAgent.buildCollection', () => { |
| 27 | + it('serialises generateFile as is_generate_file so Ruby main agents read it natively', () => { |
| 28 | + const agent = createAgent(); |
| 29 | + const collection = buildCollectionFixture({ |
| 30 | + scope: 'Single', |
| 31 | + generateFile: true, |
| 32 | + description: 'export', |
| 33 | + }); |
| 34 | + |
| 35 | + const built = agent.buildCollection(collection, {}) as { actions: Record<string, unknown> }; |
| 36 | + const action = built.actions.download as Record<string, unknown>; |
| 37 | + |
| 38 | + expect(action).toEqual({ |
| 39 | + scope: 'Single', |
| 40 | + is_generate_file: true, |
| 41 | + description: 'export', |
| 42 | + }); |
| 43 | + expect(action).not.toHaveProperty('generate_file'); |
| 44 | + expect(action).not.toHaveProperty('generateFile'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('does not introduce is_generate_file when the source schema omits generateFile', () => { |
| 48 | + const agent = createAgent(); |
| 49 | + const collection = buildCollectionFixture({ scope: 'Single' }); |
| 50 | + |
| 51 | + const built = agent.buildCollection(collection, {}) as { actions: Record<string, unknown> }; |
| 52 | + const action = built.actions.download as Record<string, unknown>; |
| 53 | + |
| 54 | + expect(action).toEqual({ scope: 'Single' }); |
| 55 | + expect(action).not.toHaveProperty('is_generate_file'); |
| 56 | + expect(action).not.toHaveProperty('generate_file'); |
| 57 | + }); |
| 58 | +}); |
0 commit comments