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 @@ -7,6 +7,7 @@ export enum BulkActionsServerEvents {
export enum BulkActionType {
Delete = 'delete',
Upload = 'upload',
Unlink = 'unlink',
}

export enum BulkActionStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
mockSocket,
mockBulkActionsAnalytics,
mockCreateBulkActionDto,
mockStandaloneRedisClient,
} from 'src/__mocks__';
import { UnlinkBulkActionSimpleRunner } from 'src/modules/bulk-actions/models/runners/simple/unlink.bulk-action.simple.runner';
import { BulkAction } from 'src/modules/bulk-actions/models/bulk-action';
import { RedisDataType } from 'src/modules/browser/keys/dto';
import { BulkActionFilter } from 'src/modules/bulk-actions/models/bulk-action-filter';

const mockBulkActionFilter = Object.assign(new BulkActionFilter(), {
count: 10_000,
match: '*',
type: RedisDataType.Set,
});

const bulkAction = new BulkAction(
mockCreateBulkActionDto.id,
mockCreateBulkActionDto.databaseId,
mockCreateBulkActionDto.type,
mockBulkActionFilter,
mockSocket,
mockBulkActionsAnalytics as any,
);

const mockKey = 'mockedKey';
const mockKeyBuffer = Buffer.from(mockKey);

describe('UnlinkBulkActionSimpleRunner', () => {
const client = mockStandaloneRedisClient;
let unlinkRunner: UnlinkBulkActionSimpleRunner;

beforeEach(() => {
unlinkRunner = new UnlinkBulkActionSimpleRunner(bulkAction, client);
});

it('prepareCommands 3 commands', () => {
const commands = unlinkRunner.prepareCommands([
mockKeyBuffer,
mockKeyBuffer,
mockKeyBuffer,
]);
expect(commands).toEqual([
['unlink', mockKeyBuffer],
['unlink', mockKeyBuffer],
['unlink', mockKeyBuffer],
]);
});

it('prepareCommands 0 commands', () => {
const commands = unlinkRunner.prepareCommands([]);
expect(commands).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AbstractBulkActionSimpleRunner } from 'src/modules/bulk-actions/models/runners/simple/abstract.bulk-action.simple.runner';
import { RedisClientCommand } from 'src/modules/redis/client';

export class UnlinkBulkActionSimpleRunner extends AbstractBulkActionSimpleRunner {
prepareCommands(keys: Buffer[]): RedisClientCommand[] {
return keys.map((key) => ['unlink', key]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ describe('BulkActionsProvider', () => {

expect(service['bulkActions'].size).toEqual(2);
});
it('should support unlink type', async () => {
const bulkAction = await service.create(
mockSessionMetadata,
{ ...mockCreateBulkActionDto, type: BulkActionType.Unlink },
mockSocket1,
);

expect(bulkAction).toBeInstanceOf(BulkAction);
expect(service['bulkActions'].size).toEqual(1);
});
it('should fail when unsupported runner class', async () => {
try {
await service.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BulkActionType,
} from 'src/modules/bulk-actions/constants';
import { DeleteBulkActionSimpleRunner } from 'src/modules/bulk-actions/models/runners/simple/delete.bulk-action.simple.runner';
import { UnlinkBulkActionSimpleRunner } from 'src/modules/bulk-actions/models/runners/simple/unlink.bulk-action.simple.runner';
import { BulkActionsAnalytics } from 'src/modules/bulk-actions/bulk-actions.analytics';
import { ClientContext, SessionMetadata } from 'src/common/models';
import { DatabaseClientFactory } from 'src/modules/database/providers/database.client.factory';
Expand Down Expand Up @@ -80,6 +81,8 @@ export class BulkActionsProvider {
switch (dto.type) {
case BulkActionType.Delete:
return DeleteBulkActionSimpleRunner;
case BulkActionType.Unlink:
return UnlinkBulkActionSimpleRunner;
default:
throw new BadRequestException(
`Unsupported type: ${dto.type} for Bulk Actions`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const deletingMock = [
id: '123',
databaseId: '1',
db: 1,
type: BulkActionsType.Delete,
type: BulkActionsType.Unlink,
filter: {
type: null,
match: '*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const BulkActionsConfig = () => {
id,
databaseId: instanceId,
db: db || 0,
type: BulkActionsType.Delete,
type: BulkActionsType.Unlink,
filter: {
type: filter,
match: search || '*',
Expand Down
1 change: 1 addition & 0 deletions redisinsight/ui/src/constants/bulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum BulkActionsServerEvent {
export enum BulkActionsType {
Delete = 'delete',
Upload = 'upload',
Unlink = 'unlink',
}

export enum BulkActionsStatus {
Expand Down
Loading