Skip to content

Commit 34f4061

Browse files
committed
Added unit tests for rdi module
1 parent 56ddb7d commit 34f4061

12 files changed

+1823
-0
lines changed

redisinsight/api/.jest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'reflect-metadata';
12
// Workaround for @Type test coverage
23
jest.mock("class-transformer", () => {
34
return {

redisinsight/api/src/__mocks__/rdi.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import {
22
Rdi,
33
RdiClientMetadata,
4+
RdiPipeline,
5+
RdiStatisticsData,
46
} from 'src/modules/rdi/models';
57
import { ApiRdiClient } from 'src/modules/rdi/client/api.rdi.client';
8+
import { RdiEntity } from 'src/modules/rdi/entities/rdi.entity';
9+
import { EncryptionStrategy } from 'src/modules/encryption/models';
10+
import { RdiDryRunJobDto } from 'src/modules/rdi/dto';
611

712
export const mockRdiId = 'rdiId';
13+
export const mockRdiPasswordEncrypted = 'password_ENCRYPTED';
14+
15+
export const mockRdiPasswordPlain = 'some pass';
816

917
export class MockRdiClient extends ApiRdiClient {
1018
constructor(metadata: RdiClientMetadata, client: any = jest.fn()) {
@@ -56,9 +64,57 @@ export const mockRdi = Object.assign(new Rdi(), {
5664
username: 'user',
5765
});
5866

67+
export const mockRdiPipeline = Object.assign(new RdiPipeline(), {
68+
jobs: { some_job: {} },
69+
config: {},
70+
});
71+
72+
export const mockRdiDryRunJob: RdiDryRunJobDto = Object.assign(new RdiDryRunJobDto(), {
73+
input_data: {},
74+
job: {},
75+
});
76+
77+
export const mockRdiStatisticsData = Object.assign(new RdiStatisticsData(), {});
78+
79+
export const mockRdiDecrypted = Object.assign(new Rdi(), {
80+
id: '1',
81+
name: 'name',
82+
version: '1.0',
83+
url: 'http://test.com',
84+
username: 'testuser',
85+
password: mockRdiPasswordPlain,
86+
lastConnection: new Date(),
87+
});
88+
89+
export const mockRdiEntityEncrypted = Object.assign(new RdiEntity(), {
90+
...mockRdiDecrypted,
91+
password: mockRdiPasswordEncrypted,
92+
encryption: EncryptionStrategy.KEYTAR,
93+
});
94+
5995
export const mockRdiUnauthorizedError = {
6096
message: 'Request failed with status code 401',
6197
response: {
6298
status: 401,
6399
},
64100
};
101+
102+
export const mockRdiRepository = jest.fn(() => ({
103+
get: jest.fn(),
104+
list: jest.fn(),
105+
create: jest.fn(),
106+
update: jest.fn(),
107+
delete: jest.fn(),
108+
}));
109+
110+
export const mockRdiClientProvider = jest.fn(() => ({
111+
getOrCreate: jest.fn(),
112+
create: jest.fn(),
113+
delete: jest.fn(),
114+
deleteById: jest.fn(),
115+
deleteManyByRdiId: jest.fn(),
116+
}));
117+
118+
export const mockRdiClientFactory = jest.fn(() => ({
119+
createClient: jest.fn(),
120+
}));

0 commit comments

Comments
 (0)