Skip to content

Commit fb3ef2a

Browse files
Merge pull request #3591 from RedisInsight/be/feature/RI-5741-rdi-unit-tests
Be/feature/ri 5741 rdi unit tests
2 parents 7c67ea2 + 3496c4a commit fb3ef2a

14 files changed

+1793
-2
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: 77 additions & 1 deletion
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()) {
@@ -15,7 +23,9 @@ export class MockRdiClient extends ApiRdiClient {
1523

1624
public getPipeline = jest.fn();
1725

18-
public getTemplate = jest.fn();
26+
public getConfigTemplate = jest.fn();
27+
28+
public getJobTemplate = jest.fn();
1929

2030
public getStrategies = jest.fn();
2131

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

69+
export const mockRdiPipeline = Object.assign(new RdiPipeline(), {
70+
jobs: { some_job: {} },
71+
config: {},
72+
});
73+
74+
export const mockRdiDryRunJob: RdiDryRunJobDto = Object.assign(new RdiDryRunJobDto(), {
75+
input_data: {},
76+
job: {},
77+
});
78+
79+
export const mockRdiStatisticsData = Object.assign(new RdiStatisticsData(), {});
80+
81+
export const mockRdiDecrypted = Object.assign(new Rdi(), {
82+
id: '1',
83+
name: 'name',
84+
version: '1.0',
85+
url: 'http://test.com',
86+
username: 'testuser',
87+
password: mockRdiPasswordPlain,
88+
lastConnection: new Date(),
89+
});
90+
91+
export const mockRdiEntityEncrypted = Object.assign(new RdiEntity(), {
92+
...mockRdiDecrypted,
93+
password: mockRdiPasswordEncrypted,
94+
encryption: EncryptionStrategy.KEYTAR,
95+
});
96+
5997
export const mockRdiUnauthorizedError = {
6098
message: 'Request failed with status code 401',
6199
response: {
62100
status: 401,
63101
},
64102
};
103+
104+
export const mockRdiRepository = jest.fn(() => ({
105+
get: jest.fn(),
106+
list: jest.fn(),
107+
create: jest.fn(),
108+
update: jest.fn(),
109+
delete: jest.fn(),
110+
}));
111+
112+
export const mockRdiClientProvider = jest.fn(() => ({
113+
getOrCreate: jest.fn(),
114+
create: jest.fn(),
115+
delete: jest.fn(),
116+
deleteById: jest.fn(),
117+
deleteManyByRdiId: jest.fn(),
118+
}));
119+
120+
export const mockRdiClientFactory = jest.fn(() => ({
121+
createClient: jest.fn(),
122+
}));
123+
124+
export const mockRdiClientStorage = jest.fn(() => ({
125+
getByMetadata: jest.fn(),
126+
set: jest.fn(),
127+
delete: jest.fn(),
128+
deleteManyByRdiId: jest.fn(),
129+
}));
130+
131+
export const mockRdiPipelineAnalytics = jest.fn(() => ({
132+
sendRdiPipelineFetched: jest.fn(),
133+
sendRdiPipelineFetchFailed: jest.fn(),
134+
sendRdiPipelineDeployed: jest.fn(),
135+
sendRdiPipelineDeployFailed: jest.fn(),
136+
}));
137+
138+
export const mockRdiAnalytics = jest.fn(() => ({
139+
sendRdiInstanceDeleted: jest.fn(),
140+
}));

redisinsight/api/src/constants/custom-error-codes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ export enum CustomErrorCodes {
5858
RdiUnauthorized = 11_402,
5959
RdiInternalServerError = 11_403,
6060
RdiValidationError = 11_404,
61+
RdiNotFound = 11_405,
6162
}

0 commit comments

Comments
 (0)