Debian Codegraph @

packages/search/lib/commands/PROFILE_AGGREGATE.spec.ts

raw
1 import { strict as assert } from 'assert';
2 import testUtils, { GLOBAL } from '../test-utils';
3 import { SchemaFieldTypes } from '.';
4 import { transformArguments } from './PROFILE_AGGREGATE';
5 import { AggregateSteps } from './AGGREGATE';
6
7 describe('PROFILE AGGREGATE', () => {
8 describe('transformArguments', () => {
9 it('without options', () => {
10 assert.deepEqual(
11 transformArguments('index', 'query'),
12 ['FT.PROFILE', 'index', 'AGGREGATE', 'QUERY', 'query']
13 );
14 });
15
16 it('with options', () => {
17 assert.deepEqual(
18 transformArguments('index', 'query', {
19 LIMITED: true,
20 VERBATIM: true,
21 STEPS: [{
22 type: AggregateSteps.SORTBY,
23 BY: '@by'
24 }]
25 }),
26 ['FT.PROFILE', 'index', 'AGGREGATE', 'LIMITED', 'QUERY', 'query',
27 'VERBATIM', 'SORTBY', '1', '@by']
28 );
29 });
30 });
31
32 testUtils.testWithClient('client.ft.search', async client => {
33 await Promise.all([
34 client.ft.create('index', {
35 field: SchemaFieldTypes.NUMERIC
36 }),
37 client.hSet('1', 'field', '1'),
38 client.hSet('2', 'field', '2')
39 ]);
40
41 const res = await client.ft.profileAggregate('index', '*');
42 assert.ok(typeof res.profile.iteratorsProfile.counter === 'number');
43 assert.ok(typeof res.profile.parsingTime === 'string');
44 assert.ok(res.results.total == 1);
45 }, GLOBAL.SERVERS.OPEN);
46 });