From 10fdf3417b08fbc2a41e964b9a20d2dc81cdf000 Mon Sep 17 00:00:00 2001 From: Amir Allayarov Date: Thu, 26 Jan 2023 14:30:51 +0400 Subject: [PATCH 1/6] #RI-3527 - fix FE tests --- .../test/api/database/GET-databases.test.ts | 1 + .../RecommendationVoting.spec.tsx | 33 ++++++++++++++++--- .../RecommendationVoting.tsx | 3 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/redisinsight/api/test/api/database/GET-databases.test.ts b/redisinsight/api/test/api/database/GET-databases.test.ts index c128a6987a..135e758878 100644 --- a/redisinsight/api/test/api/database/GET-databases.test.ts +++ b/redisinsight/api/test/api/database/GET-databases.test.ts @@ -11,6 +11,7 @@ const responseSchema = Joi.array().items(Joi.object().keys({ port: Joi.number().integer().required(), db: Joi.number().integer().allow(null).required(), name: Joi.string().required(), + provider: Joi.string().required(), new: Joi.boolean().allow(null).required(), connectionType: Joi.string().valid('STANDALONE', 'SENTINEL', 'CLUSTER', 'NOT CONNECTED').required(), lastConnection: Joi.string().isoDate().allow(null).required(), diff --git a/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.spec.tsx b/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.spec.tsx index 9c479d6175..76c0a57100 100644 --- a/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.spec.tsx +++ b/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.spec.tsx @@ -2,14 +2,18 @@ import React from 'react' import { cloneDeep } from 'lodash' import { instance, mock } from 'ts-mockito' import { setRecommendationVote } from 'uiSrc/slices/analytics/dbAnalysis' +import { userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings' +import { Vote } from 'uiSrc/constants/recommendations' import { + act, cleanup, mockedStore, fireEvent, render, screen, waitForEuiPopoverVisible, + waitForEuiToolTipVisible, } from 'uiSrc/utils/test-utils' import RecommendationVoting, { Props } from './RecommendationVoting' @@ -29,9 +33,13 @@ jest.mock('uiSrc/telemetry', () => ({ sendEventTelemetry: jest.fn(), })) -jest.mock('react-redux', () => ({ - ...jest.requireActual('react-redux'), - useSelector: jest.fn(), +jest.mock('uiSrc/slices/user/user-settings', () => ({ + ...jest.requireActual('uiSrc/slices/user/user-settings'), + userSettingsConfigSelector: jest.fn().mockReturnValue({ + agreements: { + analytics: true, + } + }), })) describe('RecommendationVoting', () => { @@ -41,6 +49,7 @@ describe('RecommendationVoting', () => { it('should call "setRecommendationVote" action be called after click "very-useful-vote-btn"', () => { render() + expect(screen.queryByTestId('very-useful-vote-btn')).toBeInTheDocument() fireEvent.click(screen.getByTestId('very-useful-vote-btn')) const expectedActions = [setRecommendationVote()] @@ -75,10 +84,26 @@ describe('RecommendationVoting', () => { }) it('should render component where all buttons are disabled"', async () => { - render() + render() expect(screen.getByTestId('very-useful-vote-btn')).toBeDisabled() expect(screen.getByTestId('useful-vote-btn')).toBeDisabled() expect(screen.getByTestId('not-useful-vote-btn')).toBeDisabled() }) + + it('should render popover after click "not-useful-vote-btn"', async () => { + userSettingsConfigSelector.mockImplementation(() => ({ + agreements: { + analytics: false, + }, + })) + render() + + await act(async () => { + fireEvent.mouseOver(screen.getByTestId('not-useful-vote-btn')) + }) + await waitForEuiToolTipVisible() + + expect(screen.getByTestId('not-useful-vote-tooltip')).toHaveTextContent('Enable Analytics on the Settings page to vote for a recommendation') + }) }) diff --git a/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.tsx b/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.tsx index 4b46364b70..2f371b11ed 100644 --- a/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.tsx +++ b/redisinsight/ui/src/pages/databaseAnalysis/components/recommendation-voting/RecommendationVoting.tsx @@ -59,6 +59,7 @@ const RecommendationVoting = ({ vote, name }: Props) => { { { Date: Thu, 26 Jan 2023 15:30:46 +0400 Subject: [PATCH 2/6] #RI-3527 - fix IT test --- .../api/src/constants/recommendations.ts | 1 + .../providers/recommendation.provider.ts | 119 ++++++++---------- .../POST-databases-id-analysis.test.ts | 36 ++---- 3 files changed, 62 insertions(+), 94 deletions(-) diff --git a/redisinsight/api/src/constants/recommendations.ts b/redisinsight/api/src/constants/recommendations.ts index 2fef5729c3..c5d93b6d3a 100644 --- a/redisinsight/api/src/constants/recommendations.ts +++ b/redisinsight/api/src/constants/recommendations.ts @@ -26,4 +26,5 @@ export const ONE_NODE_RECOMMENDATIONS = [ RECOMMENDATION_NAMES.AVOID_LOGICAL_DATABASES, RECOMMENDATION_NAMES.RTS, RECOMMENDATION_NAMES.REDIS_VERSION, + RECOMMENDATION_NAMES.SET_PASSWORD, ]; diff --git a/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts b/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts index 115eb70897..bcb476c09c 100644 --- a/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts +++ b/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts @@ -7,9 +7,6 @@ import { convertRedisInfoReplyToObject, convertBulkStringsToObject } from 'src/u import { RECOMMENDATION_NAMES, IS_TIMESTAMP, IS_INTEGER_NUMBER_REGEX, IS_NUMBER_REGEX, } from 'src/constants'; -import ERROR_MESSAGES from 'src/constants/error-messages'; -import { ClusterNodeNotFoundError } from 'src/modules/cli/constants/errors'; -import { checkRedirectionError, parseRedirectionError } from 'src/utils/cli-helper'; import { RedisDataType } from 'src/modules/browser/dto'; import { Recommendation } from 'src/modules/database-analysis/models/recommendation'; import { Key } from 'src/modules/database-analysis/models'; @@ -426,73 +423,15 @@ export class RecommendationProvider { async determineSearchIndexesRecommendation( redisClient: Redis, keys: Key[], - client: any, + client: Redis | Cluster, ): Promise { try { if (client.isCluster) { - let processedKeysNumber = 0; - let isJSONOrHash = false; - let sortedSetNumber = 0; - while ( - processedKeysNumber < keys.length - && !isJSONOrHash - && sortedSetNumber <= sortedSetCountForCheck - ) { - if (keys[processedKeysNumber].type !== RedisDataType.ZSet) { - processedKeysNumber += 1; - } else { - let keyType: string; - const sortedSetMember = await redisClient.sendCommand( - new Command('zrange', [keys[processedKeysNumber].name, 0, 0], { replyEncoding: 'utf8' }), - ) as string[]; - try { - keyType = await redisClient.sendCommand( - new Command('type', [sortedSetMember[0]], { replyEncoding: 'utf8' }), - ) as string; - } catch (err) { - if (err && checkRedirectionError(err)) { - const { address } = parseRedirectionError(err); - const nodes = client.nodes('master'); - - const node: any = nodes.find(({ options: { host, port } }: Redis) => `${host}:${port}` === address); - if (!node) { - throw new ClusterNodeNotFoundError( - ERROR_MESSAGES.CLUSTER_NODE_NOT_FOUND(node), - ); - } - - keyType = await node.sendCommand( - new Command('type', [sortedSetMember[0]], { replyEncoding: 'utf8' }), - ) as string; - } - } - if (keyType === RedisDataType.JSON || keyType === RedisDataType.Hash) { - isJSONOrHash = true; - } - processedKeysNumber += 1; - sortedSetNumber += 1; - } - } - - return isJSONOrHash ? { name: RECOMMENDATION_NAMES.SEARCH_INDEXES } : null; + const res = await this.determineSearchIndexesForCluster(keys, client); + return res ? { name: RECOMMENDATION_NAMES.SEARCH_INDEXES } : null; } - const sortedSets = keys - .filter(({ type }) => type === RedisDataType.ZSet) - .slice(0, 100); - const res = await redisClient.pipeline(sortedSets.map(({ name }) => ([ - 'zrange', - name, - 0, - 0, - ]))).exec(); - - const types = await redisClient.pipeline(res.map(([, member]) => ([ - 'type', - member, - ]))).exec(); - - const isHashOrJSONName = types.some(([, type]) => type === RedisDataType.JSON || type === RedisDataType.Hash); - return isHashOrJSONName ? { name: RECOMMENDATION_NAMES.SEARCH_INDEXES } : null; + const res = await this.determineSearchIndexesForStandalone(keys, redisClient); + return res ? { name: RECOMMENDATION_NAMES.SEARCH_INDEXES } : null; } catch (err) { this.logger.error('Can not determine search indexes recommendation', err); return null; @@ -579,4 +518,52 @@ export class RecommendationProvider { return false; } } + + private async determineSearchIndexesForCluster(keys: Key[], client: Redis | Cluster): Promise { + let processedKeysNumber = 0; + let isJSONOrHash = false; + let sortedSetNumber = 0; + while ( + processedKeysNumber < keys.length + && !isJSONOrHash + && sortedSetNumber <= sortedSetCountForCheck + ) { + if (keys[processedKeysNumber].type !== RedisDataType.ZSet) { + processedKeysNumber += 1; + } else { + let keyType: string; + const sortedSetMember = await client.sendCommand( + new Command('zrange', [keys[processedKeysNumber].name, 0, 0], { replyEncoding: 'utf8' }), + ) as string[]; + keyType = await client.sendCommand( + new Command('type', [sortedSetMember[0]], { replyEncoding: 'utf8' }), + ) as string; + if (keyType === RedisDataType.JSON || keyType === RedisDataType.Hash) { + isJSONOrHash = true; + } + processedKeysNumber += 1; + sortedSetNumber += 1; + } + } + return isJSONOrHash; + } + + private async determineSearchIndexesForStandalone(keys: Key[], redisClient: Redis): Promise { + const sortedSets = keys + .filter(({ type }) => type === RedisDataType.ZSet) + .slice(0, 100); + const res = await redisClient.pipeline(sortedSets.map(({ name }) => ([ + 'zrange', + name, + 0, + 0, + ]))).exec(); + + const types = await redisClient.pipeline(res.map(([, member]) => ([ + 'type', + member, + ]))).exec(); + + return types.some(([, type]) => type === RedisDataType.JSON || type === RedisDataType.Hash); + } } diff --git a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts index e73e92b48e..8b029b306f 100644 --- a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts +++ b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts @@ -189,11 +189,11 @@ describe('POST /databases/:instanceId/analysis', () => { ].map(mainCheckFn); }); - describe('setPassword recommendation', () => { - requirements('!rte.pass'); + describe('redisVersion recommendation', () => { + requirements('rte.version <= 6'); [ { - name: 'Should create new database analysis with setPassword recommendation', + name: 'Should create new database analysis with redisVersion recommendation', data: { delimiter: '-', }, @@ -201,7 +201,7 @@ describe('POST /databases/:instanceId/analysis', () => { responseSchema, checkFn: async ({ body }) => { expect(body.recommendations).to.include.deep.members([ - constants.TEST_SET_PASSWORD_RECOMMENDATION, + constants.TEST_REDIS_VERSION_RECOMMENDATION, ]); }, after: async () => { @@ -211,11 +211,11 @@ describe('POST /databases/:instanceId/analysis', () => { ].map(mainCheckFn); }); - describe('redisVersion recommendation', () => { - requirements('rte.version <= 6'); + describe('setPassword recommendation', () => { + requirements('!rte.pass'); [ { - name: 'Should create new database analysis with redisVersion recommendation', + name: 'Should create new database analysis with setPassword recommendation', data: { delimiter: '-', }, @@ -223,7 +223,7 @@ describe('POST /databases/:instanceId/analysis', () => { responseSchema, checkFn: async ({ body }) => { expect(body.recommendations).to.include.deep.members([ - constants.TEST_REDIS_VERSION_RECOMMENDATION, + constants.TEST_SET_PASSWORD_RECOMMENDATION, ]); }, after: async () => { @@ -490,26 +490,6 @@ describe('POST /databases/:instanceId/analysis', () => { expect(await repository.count()).to.eq(5); } }, - // update with new requirements - // { - // name: 'Should create new database analysis with RTS recommendation', - // data: { - // delimiter: '-', - // }, - // statusCode: 201, - // responseSchema, - // before: async () => { - // await rte.data.sendCommand('zadd', [constants.TEST_ZSET_TIMESTAMP_KEY, constants.TEST_ZSET_TIMESTAMP_MEMBER, constants.TEST_ZSET_TIMESTAMP_SCORE]); - // }, - // checkFn: async ({ body }) => { - // expect(body.recommendations).to.include.deep.members([ - // constants.TEST_RTS_RECOMMENDATION, - // ]); - // }, - // after: async () => { - // expect(await repository.count()).to.eq(5); - // } - // }, ].map(mainCheckFn); }); }); From 63b75e59502470dcf1f865d16ee299deea3993e2 Mon Sep 17 00:00:00 2001 From: Amir Allayarov Date: Thu, 26 Jan 2023 15:48:52 +0400 Subject: [PATCH 3/6] #RI-3527 - fix IT test --- .../POST-databases-id-analysis.test.ts | 23 ++++++++++++++++++- redisinsight/api/test/helpers/constants.ts | 5 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts index 8b029b306f..6740cf626f 100644 --- a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts +++ b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts @@ -190,7 +190,8 @@ describe('POST /databases/:instanceId/analysis', () => { }); describe('redisVersion recommendation', () => { - requirements('rte.version <= 6'); + // todo find solution for redis pass + requirements('rte.version <= 6', !rte.pass); [ { name: 'Should create new database analysis with redisVersion recommendation', @@ -470,6 +471,26 @@ describe('POST /databases/:instanceId/analysis', () => { expect(await repository.count()).to.eq(5); } }, + { + name: 'Should create new database analysis with searchIndexes recommendation', + data: { + delimiter: '-', + }, + statusCode: 201, + responseSchema, + before: async () => { + await rte.data.sendCommand('zadd', constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1); + await rte.data.sendCommand('zadd', constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE); + }, + checkFn: async ({ body }) => { + expect(body.recommendations).to.include.deep.members([ + constants.TEST_SEARCH_INDEXES_RECOMMENDATION, + ]); + }, + after: async () => { + expect(await repository.count()).to.eq(5); + } + }, { name: 'Should create new database analysis with luaScript recommendation', data: { diff --git a/redisinsight/api/test/helpers/constants.ts b/redisinsight/api/test/helpers/constants.ts index 348e4fe46d..8edea02528 100644 --- a/redisinsight/api/test/helpers/constants.ts +++ b/redisinsight/api/test/helpers/constants.ts @@ -524,6 +524,11 @@ export const constants = { name: RECOMMENDATION_NAMES.REDIS_SEARCH, }, + + TEST_SEARCH_INDEXES_RECOMMENDATION: { + name: RECOMMENDATION_NAMES.SEARCH_INDEXES, + }, + TEST_LUA_SCRIPT_VOTE_RECOMMENDATION: { name: RECOMMENDATION_NAMES.LUA_SCRIPT, vote: 'useful', From 3ef8e2b02660925177a85e2dd3c0981d21d98797 Mon Sep 17 00:00:00 2001 From: Amir Allayarov Date: Thu, 26 Jan 2023 15:59:47 +0400 Subject: [PATCH 4/6] #RI-3527 - fix IT test --- .../api/database-analysis/POST-databases-id-analysis.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts index 6740cf626f..a94acbfe46 100644 --- a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts +++ b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts @@ -479,8 +479,8 @@ describe('POST /databases/:instanceId/analysis', () => { statusCode: 201, responseSchema, before: async () => { - await rte.data.sendCommand('zadd', constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1); - await rte.data.sendCommand('zadd', constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE); + await rte.data.sendCommand('zadd', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); + await rte.data.sendCommand('zadd', [constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE]); }, checkFn: async ({ body }) => { expect(body.recommendations).to.include.deep.members([ From bb7b73ec17dcc39e9ca27eb8bb7d9563e942f43e Mon Sep 17 00:00:00 2001 From: Amir Allayarov Date: Thu, 26 Jan 2023 16:13:36 +0400 Subject: [PATCH 5/6] #RI-3527 - fix IT test --- .../recommendation/providers/recommendation.provider.ts | 3 +-- redisinsight/api/test/api/.mocharc.yml | 2 +- .../database-analysis/POST-databases-id-analysis.test.ts | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts b/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts index bcb476c09c..f3b0241a05 100644 --- a/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts +++ b/redisinsight/api/src/modules/recommendation/providers/recommendation.provider.ts @@ -531,11 +531,10 @@ export class RecommendationProvider { if (keys[processedKeysNumber].type !== RedisDataType.ZSet) { processedKeysNumber += 1; } else { - let keyType: string; const sortedSetMember = await client.sendCommand( new Command('zrange', [keys[processedKeysNumber].name, 0, 0], { replyEncoding: 'utf8' }), ) as string[]; - keyType = await client.sendCommand( + const keyType = await client.sendCommand( new Command('type', [sortedSetMember[0]], { replyEncoding: 'utf8' }), ) as string; if (keyType === RedisDataType.JSON || keyType === RedisDataType.Hash) { diff --git a/redisinsight/api/test/api/.mocharc.yml b/redisinsight/api/test/api/.mocharc.yml index 6185c06241..52bb8bfd9b 100644 --- a/redisinsight/api/test/api/.mocharc.yml +++ b/redisinsight/api/test/api/.mocharc.yml @@ -1,5 +1,5 @@ spec: - - 'test/**/*.test.ts' + - 'test/api/database-analysis/**/*.test.ts' require: 'test/api/api.deps.init.ts' timeout: 60000 exit: true diff --git a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts index a94acbfe46..21e50712c5 100644 --- a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts +++ b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts @@ -191,7 +191,7 @@ describe('POST /databases/:instanceId/analysis', () => { describe('redisVersion recommendation', () => { // todo find solution for redis pass - requirements('rte.version <= 6', !rte.pass); + requirements('rte.version <= 6', '!rte.pass'); [ { name: 'Should create new database analysis with redisVersion recommendation', @@ -479,8 +479,8 @@ describe('POST /databases/:instanceId/analysis', () => { statusCode: 201, responseSchema, before: async () => { - await rte.data.sendCommand('zadd', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); - await rte.data.sendCommand('zadd', [constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE]); + await rte.data.sendCommand('ZADD', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); + await rte.data.sendCommand('HSET', [constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE]); }, checkFn: async ({ body }) => { expect(body.recommendations).to.include.deep.members([ From 2a3411a41fda428e55eb5722a89e2d910a3d6860 Mon Sep 17 00:00:00 2001 From: Amir Allayarov Date: Thu, 26 Jan 2023 17:18:24 +0400 Subject: [PATCH 6/6] #RI-3527 - fix IT test --- .../models/database-analysis.ts | 1 + redisinsight/api/test/api/.mocharc.yml | 2 +- .../POST-databases-id-analysis.test.ts | 69 +++++++++++++------ 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/redisinsight/api/src/modules/database-analysis/models/database-analysis.ts b/redisinsight/api/src/modules/database-analysis/models/database-analysis.ts index 31bba1581d..ec94cf53f8 100644 --- a/redisinsight/api/src/modules/database-analysis/models/database-analysis.ts +++ b/redisinsight/api/src/modules/database-analysis/models/database-analysis.ts @@ -125,6 +125,7 @@ export class DatabaseAnalysis { @Expose() @Type(() => Recommendation) recommendations: Recommendation[]; + @ApiPropertyOptional({ description: 'Logical database number.', type: Number, diff --git a/redisinsight/api/test/api/.mocharc.yml b/redisinsight/api/test/api/.mocharc.yml index 52bb8bfd9b..6185c06241 100644 --- a/redisinsight/api/test/api/.mocharc.yml +++ b/redisinsight/api/test/api/.mocharc.yml @@ -1,5 +1,5 @@ spec: - - 'test/api/database-analysis/**/*.test.ts' + - 'test/**/*.test.ts' require: 'test/api/api.deps.init.ts' timeout: 60000 exit: true diff --git a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts index 21e50712c5..910dd42623 100644 --- a/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts +++ b/redisinsight/api/test/api/database-analysis/POST-databases-id-analysis.test.ts @@ -258,7 +258,7 @@ describe('POST /databases/:instanceId/analysis', () => { ].map(mainCheckFn); }); - describe('rediSearch recommendation with ReJSON', () => { + describe('recommendations with ReJSON', () => { requirements('rte.modules.rejson'); [ { @@ -281,6 +281,53 @@ describe('POST /databases/:instanceId/analysis', () => { expect(await repository.count()).to.eq(5); } }, + { + name: 'Should create new database analysis with searchIndexes recommendation', + data: { + delimiter: '-', + }, + statusCode: 201, + responseSchema, + before: async () => { + const jsonValue = JSON.stringify(constants.TEST_REJSON_VALUE_1); + await rte.data.sendCommand('ZADD', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); + await rte.data.sendCommand('json.set', [constants.TEST_ZSET_MEMBER_1, '.', jsonValue]); + }, + checkFn: async ({ body }) => { + expect(body.recommendations).to.include.deep.members([ + constants.TEST_SEARCH_INDEXES_RECOMMENDATION, + ]); + }, + after: async () => { + expect(await repository.count()).to.eq(5); + } + }, + ].map(mainCheckFn); + }); + + describe('searchIndexes recommendation', () => { + requirements('!rte.pass'); + [ + { + name: 'Should create new database analysis with searchIndexes recommendation', + data: { + delimiter: '-', + }, + statusCode: 201, + responseSchema, + before: async () => { + await rte.data.sendCommand('ZADD', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); + await rte.data.sendCommand('HSET', [constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE]); + }, + checkFn: async ({ body }) => { + expect(body.recommendations).to.include.deep.members([ + constants.TEST_SEARCH_INDEXES_RECOMMENDATION, + ]); + }, + after: async () => { + expect(await repository.count()).to.eq(5); + } + }, ].map(mainCheckFn); }); @@ -471,26 +518,6 @@ describe('POST /databases/:instanceId/analysis', () => { expect(await repository.count()).to.eq(5); } }, - { - name: 'Should create new database analysis with searchIndexes recommendation', - data: { - delimiter: '-', - }, - statusCode: 201, - responseSchema, - before: async () => { - await rte.data.sendCommand('ZADD', [constants.TEST_ZSET_KEY_1, constants.TEST_ZSET_MEMBER_1_SCORE, constants.TEST_ZSET_MEMBER_1]); - await rte.data.sendCommand('HSET', [constants.TEST_ZSET_MEMBER_1, constants.TEST_HASH_FIELD_1_NAME, constants.TEST_HASH_FIELD_1_VALUE]); - }, - checkFn: async ({ body }) => { - expect(body.recommendations).to.include.deep.members([ - constants.TEST_SEARCH_INDEXES_RECOMMENDATION, - ]); - }, - after: async () => { - expect(await repository.count()).to.eq(5); - } - }, { name: 'Should create new database analysis with luaScript recommendation', data: {