Skip to content

Commit 8c47ab8

Browse files
#RI-2509-resolve comments
1 parent 9ac438e commit 8c47ab8

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

redisinsight/api/src/modules/workbench/providers/command-execution.provider.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,33 @@ describe('CommandExecutionProvider', () => {
140140
}),
141141
]));
142142
});
143+
it('should return with flag isNotStored="true" even if size limit exceeded', async () => {
144+
repository.save.mockReturnValueOnce([mockCommandExecutionEntity]);
145+
encryptionService.encrypt.mockReturnValue(mockEncryptResult);
146+
147+
const executionResult = [new CommandExecutionResult({
148+
status: CommandExecutionStatus.Success,
149+
response: `${Buffer.alloc(WORKBENCH_CONFIG.maxResultSize, 'a').toString()}`,
150+
})];
151+
152+
expect(await service.createMany([{
153+
...mockCommandExecutionPartial,
154+
result: executionResult,
155+
}])).toEqual([new CommandExecution({
156+
...mockCommandExecutionPartial,
157+
id: mockCommandExecutionEntity.id,
158+
createdAt: mockCommandExecutionEntity.createdAt,
159+
result: executionResult,
160+
isNotStored: true,
161+
})]);
162+
163+
expect(encryptionService.encrypt).toHaveBeenLastCalledWith(JSON.stringify([
164+
new CommandExecutionResult({
165+
status: CommandExecutionStatus.Success,
166+
response: 'Results have been deleted since they exceed 1 MB. Re-run the command to see new results.',
167+
}),
168+
]));
169+
})
143170
});
144171
describe('getList', () => {
145172
it('should return list (2) of command execution', async () => {

redisinsight/api/src/modules/workbench/providers/command-execution.provider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ export class CommandExecutionProvider {
3131
*/
3232
async createMany(commandExecutions: Partial<CommandExecution>[]): Promise<CommandExecution[]> {
3333
// todo: limit by 30 max to insert
34-
const notStoredIndexes = {};
3534
let entities = await Promise.all(commandExecutions.map(async (commandExecution, idx) => {
3635
const entity = plainToClass(CommandExecutionEntity, commandExecution);
3736

3837
// Do not store command execution result that exceeded limitation
3938
if (JSON.stringify(entity.result).length > WORKBENCH_CONFIG.maxResultSize) {
40-
notStoredIndexes[idx] = true;
4139
entity.result = JSON.stringify([
4240
{
4341
status: CommandExecutionStatus.Success,
4442
response: ERROR_MESSAGES.WORKBENCH_RESPONSE_TOO_BIG(),
4543
},
4644
]);
45+
// Hack, do not store isNotStored. Send once to show warning
46+
entity['isNotStored'] = true;
4747
}
4848

4949
return this.encryptEntity(entity);
@@ -61,7 +61,6 @@ export class CommandExecutionProvider {
6161
result: commandExecutions[idx].result,
6262
nodeOptions: commandExecutions[idx].nodeOptions,
6363
summary: commandExecutions[idx].summary,
64-
isNotStored: notStoredIndexes[idx] || false,
6564
},
6665
)),
6766
);

redisinsight/ui/src/components/query-card/QueryCardCliResultWrapper/QueryCardCliResultWrapper.spec.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cloneDeep } from 'lodash'
22
import React from 'react'
33
import { instance, mock } from 'ts-mockito'
4-
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
4+
import { cleanup, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
55
import { ResultsMode } from 'uiSrc/slices/interfaces/workbench'
66
import QueryCardCliResultWrapper, { Props } from './QueryCardCliResultWrapper'
77
import QueryCardCliDefaultResult, { Props as QueryCardCliDefaultResultProps } from '../QueryCardCliDefaultResult'
@@ -37,14 +37,12 @@ describe('QueryCardCliResultWrapper', () => {
3737
status: 'success'
3838
}]
3939

40-
const { queryByTestId } = render(
40+
render(
4141
<QueryCardCliResultWrapper {...instance(mockedProps)} result={mockResult} />
4242
)
4343

44-
const resultEl = queryByTestId('query-cli-result')
45-
46-
expect(resultEl).toBeInTheDocument()
47-
expect(resultEl).toHaveTextContent(mockResult?.[0]?.response)
44+
expect(screen.queryByTestId('query-cli-result')).toBeInTheDocument()
45+
expect(screen.queryByTestId('query-cli-result')).toHaveTextContent(mockResult?.[0]?.response)
4846
})
4947

5048
it('Result element should render (nil) result', () => {
@@ -53,13 +51,11 @@ describe('QueryCardCliResultWrapper', () => {
5351
status: 'success'
5452
}]
5553

56-
const { queryByTestId } = render(
54+
render(
5755
<QueryCardCliResultWrapper {...instance(mockedProps)} result={mockResult} />
5856
)
5957

60-
const resultEl = queryByTestId('query-cli-result')
61-
62-
expect(resultEl).toHaveTextContent('(nil)')
58+
expect(screen.queryByTestId('query-cli-result')).toHaveTextContent('(nil)')
6359
})
6460

6561
it('should render QueryCardCliDefaultResult', () => {
@@ -93,22 +89,18 @@ describe('QueryCardCliResultWrapper', () => {
9389
})
9490

9591
it('Should render loader', () => {
96-
const { queryByTestId } = render(
92+
render(
9793
<QueryCardCliResultWrapper {...instance(mockedProps)} loading />
9894
)
9995

100-
const loader = queryByTestId('query-cli-loader')
101-
102-
expect(loader).toBeInTheDocument()
96+
expect(screen.queryByTestId('query-cli-loader')).toBeInTheDocument()
10397
})
10498

10599
it('should render warning', () => {
106-
const { queryByTestId } = render(
100+
render(
107101
<QueryCardCliResultWrapper {...instance(mockedProps)} isNotStored />
108102
)
109103

110-
const warning = queryByTestId('query-cli-warning')
111-
112-
expect(warning).toBeInTheDocument()
104+
expect(screen.queryByTestId('query-cli-warning')).toBeInTheDocument()
113105
})
114106
})

redisinsight/ui/src/utils/tests/cliHelper.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
cliParseCommandsGroupResult,
55
} from 'uiSrc/utils'
66
import { MOCK_COMMANDS_SPEC } from 'uiSrc/constants'
7-
import { render } from 'uiSrc/utils/test-utils'
7+
import { render, screen } from 'uiSrc/utils/test-utils'
88

99
const getDbIndexFromSelectQueryTests = [
1010
{ input: 'select 0', expected: 0 },
@@ -62,14 +62,10 @@ describe('cliParseCommandsGroupResult', () => {
6262
status: 'success'
6363
}
6464
const mockIndex = 0
65-
const { queryByTestId, getByText } = render(cliParseCommandsGroupResult(mockResult, mockIndex))
66-
const cliCommandEl = queryByTestId('wb-command')
67-
const cliCommandResultEl = queryByTestId('wb-command-result')
68-
const cliCommandTextEl = getByText('> command')
69-
const cliCommandResultTextEl = getByText('response')
65+
render(cliParseCommandsGroupResult(mockResult, mockIndex))
7066

71-
expect(cliCommandEl).toBeInTheDocument()
72-
expect(cliCommandResultEl).toBeInTheDocument()
73-
expect(cliCommandTextEl).toBeInTheDocument()
74-
expect(cliCommandResultTextEl).toBeInTheDocument()
67+
expect(screen.queryByTestId('wb-command')).toBeInTheDocument()
68+
expect(screen.queryByTestId('wb-command-result')).toBeInTheDocument()
69+
expect(screen.getByText('> command')).toBeInTheDocument()
70+
expect(screen.getByText('response')).toBeInTheDocument()
7571
})

0 commit comments

Comments
 (0)