diff --git a/packages/search/lib/commands/AGGREGATE.spec.ts b/packages/search/lib/commands/AGGREGATE.spec.ts index 420911c5600..3c7a24ad4ab 100644 --- a/packages/search/lib/commands/AGGREGATE.spec.ts +++ b/packages/search/lib/commands/AGGREGATE.spec.ts @@ -4,7 +4,7 @@ import AGGREGATE from './AGGREGATE'; import { parseArgs } from '@redis/client/lib/commands/generic-transformers'; import { DEFAULT_DIALECT } from '../dialect/default'; -describe('AGGREGATE', () => { +describe('AGGREGATE', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( @@ -27,7 +27,7 @@ describe('AGGREGATE', () => { parseArgs(AGGREGATE, 'index', '*', { ADDSCORES: true }), ['FT.AGGREGATE', 'index', '*', 'ADDSCORES', 'DIALECT', DEFAULT_DIALECT] ); - }); + }); describe('with LOAD', () => { describe('single', () => { @@ -476,7 +476,7 @@ describe('AGGREGATE', () => { }); }); - testUtils.testWithClient('client.ft.aggregate', async client => { + testUtils.testAllAuto('client.ft.aggregate', async client => { await Promise.all([ client.ft.create('index', { field: 'NUMERIC' diff --git a/packages/test-utils/lib/index.ts b/packages/test-utils/lib/index.ts index 1a9d1c9845a..7cb16bfa49c 100644 --- a/packages/test-utils/lib/index.ts +++ b/packages/test-utils/lib/index.ts @@ -590,6 +590,61 @@ export default class TestUtils { this.testWithCluster(`cluster.${title}`, fn, options.cluster); } + /** + * Tests with both a regular client and a cluster client, automatically generating the cluster + * configuration from the client configuration. + * + * Modules, functions, and scripts are placed at the cluster level, while other client options + * (password, socket, etc.) are placed under cluster defaults. + * + * @param title - The test title + * @param fn - The test function + * @param clientOptions - Client test options (cluster config will be auto-generated) + */ + testAllAuto< + M extends RedisModules = {}, + F extends RedisFunctions = {}, + S extends RedisScripts = {}, + RESP extends RespVersions = 2, + TYPE_MAPPING extends TypeMapping = {} + // POLICIES extends CommandPolicies = {} + >( + title: string, + fn: (client: RedisClientType | RedisClusterType) => unknown, + clientOptions: ClientTestOptions + ) { + this.testWithClient(`client.${title}`, fn, clientOptions); + + // Auto-generate cluster configuration from client options + const clusterOptions: ClusterTestOptions = { + serverArguments: clientOptions.serverArguments, + minimumDockerVersion: clientOptions.minimumDockerVersion, + skipTest: clientOptions.skipTest, + clusterConfiguration: {} + }; + + if (clientOptions.clientOptions) { + const { modules, functions, scripts, ...clientDefaults } = clientOptions.clientOptions as any; + + if (modules) { + clusterOptions.clusterConfiguration!.modules = modules; + } + if (functions) { + clusterOptions.clusterConfiguration!.functions = functions; + } + if (scripts) { + clusterOptions.clusterConfiguration!.scripts = scripts; + } + + // Other client options go under defaults + if (Object.keys(clientDefaults).length > 0) { + clusterOptions.clusterConfiguration!.defaults = clientDefaults; + } + } + + this.testWithCluster(`cluster.${title}`, fn, clusterOptions); + } + spawnRedisServer< M extends RedisModules = {},