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
1 change: 1 addition & 0 deletions redisinsight/api/.jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata';
// Workaround for @Type test coverage
jest.mock("class-transformer", () => {
return {
Expand Down
78 changes: 77 additions & 1 deletion redisinsight/api/src/__mocks__/rdi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {
Rdi,
RdiClientMetadata,
RdiPipeline,
RdiStatisticsData,
} from 'src/modules/rdi/models';
import { ApiRdiClient } from 'src/modules/rdi/client/api.rdi.client';
import { RdiEntity } from 'src/modules/rdi/entities/rdi.entity';
import { EncryptionStrategy } from 'src/modules/encryption/models';
import { RdiDryRunJobDto } from 'src/modules/rdi/dto';

export const mockRdiId = 'rdiId';
export const mockRdiPasswordEncrypted = 'password_ENCRYPTED';

export const mockRdiPasswordPlain = 'some pass';

export class MockRdiClient extends ApiRdiClient {
constructor(metadata: RdiClientMetadata, client: any = jest.fn()) {
Expand All @@ -15,7 +23,9 @@ export class MockRdiClient extends ApiRdiClient {

public getPipeline = jest.fn();

public getTemplate = jest.fn();
public getConfigTemplate = jest.fn();

public getJobTemplate = jest.fn();

public getStrategies = jest.fn();

Expand Down Expand Up @@ -56,9 +66,75 @@ export const mockRdi = Object.assign(new Rdi(), {
username: 'user',
});

export const mockRdiPipeline = Object.assign(new RdiPipeline(), {
jobs: { some_job: {} },
config: {},
});

export const mockRdiDryRunJob: RdiDryRunJobDto = Object.assign(new RdiDryRunJobDto(), {
input_data: {},
job: {},
});

export const mockRdiStatisticsData = Object.assign(new RdiStatisticsData(), {});

export const mockRdiDecrypted = Object.assign(new Rdi(), {
id: '1',
name: 'name',
version: '1.0',
url: 'http://test.com',
username: 'testuser',
password: mockRdiPasswordPlain,
lastConnection: new Date(),
});

export const mockRdiEntityEncrypted = Object.assign(new RdiEntity(), {
...mockRdiDecrypted,
password: mockRdiPasswordEncrypted,
encryption: EncryptionStrategy.KEYTAR,
});

export const mockRdiUnauthorizedError = {
message: 'Request failed with status code 401',
response: {
status: 401,
},
};

export const mockRdiRepository = jest.fn(() => ({
get: jest.fn(),
list: jest.fn(),
create: jest.fn(),
update: jest.fn(),
delete: jest.fn(),
}));

export const mockRdiClientProvider = jest.fn(() => ({
getOrCreate: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
deleteById: jest.fn(),
deleteManyByRdiId: jest.fn(),
}));

export const mockRdiClientFactory = jest.fn(() => ({
createClient: jest.fn(),
}));

export const mockRdiClientStorage = jest.fn(() => ({
getByMetadata: jest.fn(),
set: jest.fn(),
delete: jest.fn(),
deleteManyByRdiId: jest.fn(),
}));

export const mockRdiPipelineAnalytics = jest.fn(() => ({
sendRdiPipelineFetched: jest.fn(),
sendRdiPipelineFetchFailed: jest.fn(),
sendRdiPipelineDeployed: jest.fn(),
sendRdiPipelineDeployFailed: jest.fn(),
}));

export const mockRdiAnalytics = jest.fn(() => ({
sendRdiInstanceDeleted: jest.fn(),
}));
1 change: 1 addition & 0 deletions redisinsight/api/src/constants/custom-error-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export enum CustomErrorCodes {
RdiUnauthorized = 11_402,
RdiInternalServerError = 11_403,
RdiValidationError = 11_404,
RdiNotFound = 11_405,
}
Loading