Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export abstract class CommandExecutionRepository {
abstract getList(databaseId: string): Promise<ShortCommandExecution[]>;
abstract getOne(databaseId: string, id: string): Promise<CommandExecution>;
abstract delete(databaseId: string, id: string): Promise<void>;
abstract deleteAll(databaseId: string): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ describe('LocalCommandExecutionRepository', () => {
);
});
});
describe('deleteAll', () => {
it('Should not return anything on delete', async () => {
repository.delete.mockResolvedValueOnce(1);
expect(await service.deleteAll(mockDatabase.id)).toEqual(
undefined,
);
});
});
describe('cleanupDatabaseHistory', () => {
it('Should should not return anything on cleanup', async () => {
mockQueryBuilderGetManyRaw.mockReturnValueOnce([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ export class LocalCommandExecutionRepository extends CommandExecutionRepository
this.logger.log('Command execution deleted');
}

/**
* Delete all items
*
* @param databaseId
*/
async deleteAll(databaseId: string): Promise<void> {
this.logger.log('Delete all command executions');

await this.commandExecutionRepository.delete({ databaseId });

this.logger.log('Command executions deleted');
}

/**
* Clean history for particular database to fit 30 items limitation
* @param databaseId
Expand Down
12 changes: 12 additions & 0 deletions redisinsight/api/src/modules/workbench/workbench.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ export class WorkbenchController {
): Promise<void> {
return this.service.deleteCommandExecution(databaseId, id);
}

@ApiEndpoint({
description: 'Delete command executions',
statusCode: 200,
})
@Delete('/command-executions')
@ApiRedisParams()
async deleteCommandExecutions(
@Param('dbInstance') databaseId: string,
): Promise<void> {
return this.service.deleteCommandExecutions(databaseId);
}
}
12 changes: 12 additions & 0 deletions redisinsight/api/src/modules/workbench/workbench.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const mockCommandExecutionRepository = () => ({
getList: jest.fn(),
getOne: jest.fn(),
delete: jest.fn(),
deleteAll: jest.fn(),
});

describe('WorkbenchService', () => {
Expand Down Expand Up @@ -389,6 +390,17 @@ describe('WorkbenchService', () => {
mockCommandExecution.id,
);

expect(result).toEqual(undefined);
});
});
describe('deleteCommandExecutions', () => {
it('should not return anything on delete', async () => {
commandExecutionProvider.deleteAll.mockResolvedValueOnce('some response');

const result = await service.deleteCommandExecutions(
mockWorkbenchClientMetadata.databaseId,
);

expect(result).toEqual(undefined);
});
});
Expand Down
9 changes: 9 additions & 0 deletions redisinsight/api/src/modules/workbench/workbench.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ export class WorkbenchService {
this.analyticsService.sendCommandDeletedEvent(databaseId);
}

/**
* Delete command executions by databaseId
*
* @param databaseId
*/
async deleteCommandExecutions(databaseId: string): Promise<void> {
await this.commandExecutionRepository.deleteAll(databaseId);
}

/**
* Check if workbench allows such command
* @param commandLine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
expect,
describe,
it,
deps,
validateApiCall,
} from '../deps';
const { server, request, constants, rte, localDb } = deps;

// endpoint to test
const endpoint = (
instanceId = constants.TEST_INSTANCE_ID,
) =>
request(server).delete(`/${constants.API.DATABASES}/${instanceId}/workbench/command-executions`);

const mainCheckFn = async (testCase) => {
it(testCase.name, async () => {
// additional checks before test run
if (testCase.before) {
await testCase.before();
}

await validateApiCall({
endpoint,
...testCase,
});

// additional checks after test pass
if (testCase.after) {
await testCase.after();
}
});
};

describe('DELETE /databases/:instanceId/workbench/command-executions', () => {
describe('Common', () => {
[
{
name: 'Should return 404 not found when incorrect instance',
endpoint: () => endpoint(
constants.TEST_NOT_EXISTED_INSTANCE_ID,
),
statusCode: 404,
responseBody: {
statusCode: 404,
message: 'Invalid database instance id.',
error: 'Not Found'
},
},
{
name: 'Should return 0 array when no history items yet',
before: async () => {
await localDb.generateNCommandExecutions({
databaseId: constants.TEST_INSTANCE_ID,
id: constants.TEST_COMMAND_EXECUTION_ID_1,
}, 2);
},
after: async () => {
expect(await (await localDb.getRepository(localDb.repositories.COMMAND_EXECUTION)).count({})).to.eq(0)
},
},
].map(mainCheckFn);
});
});