Skip to content

Commit 2986421

Browse files
Merge pull request #1411 from RedisInsight/be/feature/change_error_text
change error text
2 parents b51535f + da2eff2 commit 2986421

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

redisinsight/api/src/modules/browser/services/redisearch/redisearch.service.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ describe('RedisearchService', () => {
222222
cursor: mockSearchRedisearchDto.limit + mockSearchRedisearchDto.offset,
223223
scanned: 2,
224224
total: 100,
225+
maxResults: null,
225226
keys: [{
226227
name: keyName1,
227228
}, {
228229
name: keyName2,
229230
}],
230231
});
231232

232-
expect(nodeClient.sendCommand).toHaveBeenCalledTimes(1);
233+
expect(nodeClient.sendCommand).toHaveBeenCalledTimes(2);
233234
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
234235
name: 'FT.SEARCH',
235236
args: [
@@ -239,6 +240,13 @@ describe('RedisearchService', () => {
239240
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
240241
],
241242
}));
243+
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
244+
name: 'FT.CONFIG',
245+
args: [
246+
'GET',
247+
'MAXSEARCHRESULTS',
248+
],
249+
}));
242250
});
243251
it('should search in cluster', async () => {
244252
browserTool.getRedisClient.mockResolvedValue(clusterClient);
@@ -252,13 +260,14 @@ describe('RedisearchService', () => {
252260
cursor: mockSearchRedisearchDto.limit + mockSearchRedisearchDto.offset,
253261
scanned: 2,
254262
total: 100,
263+
maxResults: null,
255264
keys: [
256265
{ name: keyName1 },
257266
{ name: keyName2 },
258267
],
259268
});
260269

261-
expect(clusterClient.sendCommand).toHaveBeenCalledTimes(1);
270+
expect(clusterClient.sendCommand).toHaveBeenCalledTimes(2);
262271
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
263272
name: 'FT.SEARCH',
264273
args: [
@@ -268,6 +277,13 @@ describe('RedisearchService', () => {
268277
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
269278
],
270279
}));
280+
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
281+
name: 'FT.CONFIG',
282+
args: [
283+
'GET',
284+
'MAXSEARCHRESULTS',
285+
],
286+
}));
271287
});
272288
it('should handle ACL error (ft.info command)', async () => {
273289
when(nodeClient.sendCommand)

redisinsight/api/src/modules/browser/services/redisearch/redisearch.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { GetKeysWithDetailsResponse } from 'src/modules/browser/dto';
1818
import { RedisErrorCodes } from 'src/constants';
1919
import { plainToClass } from 'class-transformer';
20+
import { numberWithSpaces } from 'src/utils/base.helper';
2021
import { BrowserToolService } from '../browser-tool/browser-tool.service';
2122

2223
@Injectable()
@@ -174,7 +175,7 @@ export class RedisearchService {
174175
} catch (error) {
175176
this.logger.error('Failed to search keys using redisearch index', error);
176177
if (error.message?.includes(RedisErrorCodes.RedisearchLimit)) {
177-
throw new BadRequestException(ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(dto.limit?.toLocaleString?.()));
178+
throw new BadRequestException(ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(numberWithSpaces(dto.limit)));
178179
}
179180
throw catchAclError(error);
180181
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { numberWithSpaces } from 'src/utils/base.helper';
2+
3+
const numberWithSpacesTests = [
4+
{ input: 0, output: '0' },
5+
{ input: 10, output: '10' },
6+
{ input: 100, output: '100' },
7+
{ input: 1000, output: '1 000' },
8+
{ input: 1000.001, output: '1 000.001' },
9+
{ input: 5500, output: '5 500' },
10+
{ input: 1000000, output: '1 000 000' },
11+
{ input: 1233543234543243, output: '1 233 543 234 543 243' },
12+
{ input: NaN, output: 'NaN' },
13+
];
14+
15+
describe('numberWithSpaces', () => {
16+
numberWithSpacesTests.forEach((test) => {
17+
it(`should be output: ${test.output} for input: ${test.input} `, async () => {
18+
const result = numberWithSpaces(test.input);
19+
20+
expect(result).toEqual(test.output);
21+
});
22+
});
23+
});

redisinsight/api/src/utils/base.helper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ export const sortByNumberField = <T>(
44
items: T[],
55
field: string,
66
): T[] => sortBy(items, (o) => (o && isNumber(o[field]) ? o[field] : -Infinity));
7+
8+
9+
export const numberWithSpaces = (number: number = 0) =>
10+
number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ')

redisinsight/api/test/api/redisearch/POST-databases-id-redisearch-search.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { numberWithSpaces } from 'src/utils/base.helper';
12
import {
23
expect,
34
describe,
@@ -89,7 +90,7 @@ describe('POST /databases/:id/redisearch/search', () => {
8990
responseBody: {
9091
statusCode: 400,
9192
error: 'Bad Request',
92-
message: `Use a minimum of ${validInputData.limit} as the LIMIT.`,
93+
message: `Set MAXSEARCHRESULTS to at least ${numberWithSpaces(validInputData.limit)}.`,
9394
},
9495
before: () => rte.data.setRedisearchConfig('MAXSEARCHRESULTS', '1'),
9596
after: () => rte.data.setRedisearchConfig('MAXSEARCHRESULTS', '10000'),

0 commit comments

Comments
 (0)