1
1
import { Database } from 'src/modules/database/models/database' ;
2
- import {
3
- mockCaCertificate ,
4
- mockClientCertificate ,
5
- } from 'src/__mocks__/certificates' ;
2
+ import { mockCaCertificate , mockClientCertificate } from 'src/__mocks__/certificates' ;
6
3
import { SentinelMaster } from 'src/modules/redis-sentinel/models/sentinel-master' ;
7
4
import { ConnectionType , DatabaseEntity } from 'src/modules/database/entities/database.entity' ;
8
5
import { EncryptionStrategy } from 'src/modules/encryption/models' ;
9
6
import { mockIORedisClient } from 'src/__mocks__/redis' ;
7
+ import { mockSentinelMasterDto } from 'src/__mocks__/redis-sentinel' ;
8
+ import { pick } from 'lodash' ;
9
+ import { RedisDatabaseInfoResponse } from 'src/modules/database/dto/redis-info.dto' ;
10
+ import { ClientMetadata } from 'src/modules/redis/models/client-metadata' ;
11
+ import { AppTool } from 'src/models' ;
12
+ import { DatabaseOverview } from 'src/modules/database/models/database-overview' ;
10
13
11
14
export const mockDatabaseId = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-db-id' ;
12
15
@@ -21,8 +24,8 @@ export const mockDatabaseSentinelMasterPasswordPlain = 'some sentinel pass';
21
24
export const mockDatabase = Object . assign ( new Database ( ) , {
22
25
id : mockDatabaseId ,
23
26
name : 'database-name' ,
24
- host : 'localhost ' ,
25
- port : 3679 ,
27
+ host : '127.0.100.1 ' ,
28
+ port : 6379 ,
26
29
connectionType : ConnectionType . STANDALONE ,
27
30
} ) ;
28
31
@@ -69,7 +72,7 @@ export const mockDatabaseWithTlsAuthEntity = Object.assign(new DatabaseEntity(),
69
72
} ) ;
70
73
71
74
export const mockSentinelMaster = Object . assign ( new SentinelMaster ( ) , {
72
- name : 'master_group_name ' ,
75
+ name : 'mymaster ' ,
73
76
username : 'master_group_username' ,
74
77
password : mockDatabaseSentinelMasterPasswordPlain ,
75
78
} ) ;
@@ -78,6 +81,7 @@ export const mockSentinelDatabaseWithTlsAuth = Object.assign(new Database(), {
78
81
...mockDatabaseWithTlsAuth ,
79
82
sentinelMaster : mockSentinelMaster ,
80
83
connectionType : ConnectionType . SENTINEL ,
84
+ nodes : mockSentinelMasterDto . nodes ,
81
85
} ) ;
82
86
83
87
export const mockSentinelDatabaseWithTlsAuthEntity = Object . assign ( new DatabaseEntity ( ) , {
@@ -86,18 +90,83 @@ export const mockSentinelDatabaseWithTlsAuthEntity = Object.assign(new DatabaseE
86
90
sentinelMasterUsername : mockSentinelMaster . username ,
87
91
sentinelMasterPassword : mockDatabaseSentinelMasterPasswordEncrypted ,
88
92
connectionType : ConnectionType . SENTINEL ,
93
+ nodes : JSON . stringify ( mockSentinelDatabaseWithTlsAuth . nodes ) ,
89
94
} ) ;
95
+ export const mockClusterNodes = [
96
+ {
97
+ host : '127.0.100.1' ,
98
+ port : 6379 ,
99
+ } ,
100
+ {
101
+ host : '127.0.100.2' ,
102
+ port : 6379 ,
103
+ } ,
104
+ ] ;
90
105
91
106
export const mockClusterDatabaseWithTlsAuth = Object . assign ( new Database ( ) , {
92
107
...mockDatabaseWithTlsAuth ,
93
108
connectionType : ConnectionType . CLUSTER ,
109
+ nodes : mockClusterNodes ,
94
110
} ) ;
95
111
96
112
export const mockClusterDatabaseWithTlsAuthEntity = Object . assign ( new DatabaseEntity ( ) , {
97
113
...mockDatabaseWithTlsAuthEntity ,
98
114
connectionType : ConnectionType . CLUSTER ,
115
+ nodes : JSON . stringify ( mockClusterNodes ) ,
99
116
} ) ;
100
117
118
+ export const mockClientMetadata : ClientMetadata = {
119
+ databaseId : mockDatabase . id ,
120
+ namespace : AppTool . Common ,
121
+ } ;
122
+
123
+ export const mockDatabaseOverview : DatabaseOverview = {
124
+ version : '6.2.4' ,
125
+ usedMemory : 1 ,
126
+ totalKeys : 2 ,
127
+ totalKeysPerDb : {
128
+ db0 : 1 ,
129
+ } ,
130
+ connectedClients : 1 ,
131
+ opsPerSecond : 1 ,
132
+ networkInKbps : 1 ,
133
+ networkOutKbps : 1 ,
134
+ cpuUsagePercentage : null ,
135
+ } ;
136
+
137
+ export const mockRedisServerInfoDto = {
138
+ redis_version : '6.0.5' ,
139
+ redis_mode : 'standalone' ,
140
+ os : 'Linux 4.15.0-1087-gcp x86_64' ,
141
+ arch_bits : '64' ,
142
+ tcp_port : '11113' ,
143
+ uptime_in_seconds : '1000' ,
144
+ } ;
145
+
146
+ export const mockRedisGeneralInfo : RedisDatabaseInfoResponse = {
147
+ version : mockRedisServerInfoDto . redis_version ,
148
+ databases : 16 ,
149
+ role : 'master' ,
150
+ server : mockRedisServerInfoDto ,
151
+ usedMemory : 1000000 ,
152
+ totalKeys : 1 ,
153
+ connectedClients : 1 ,
154
+ uptimeInSeconds : 1000 ,
155
+ hitRatio : 1 ,
156
+ } ;
157
+
158
+ export const mockDatabaseRepository = jest . fn ( ( ) => ( {
159
+ exists : jest . fn ( ) . mockResolvedValue ( true ) ,
160
+ get : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
161
+ create : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
162
+ update : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
163
+ delete : jest . fn ( ) ,
164
+ list : jest . fn ( ) . mockResolvedValue ( [
165
+ pick ( mockDatabase , 'id' , 'name' ) ,
166
+ pick ( mockDatabase , 'id' , 'name' ) ,
167
+ ] ) ,
168
+ } ) ) ;
169
+
101
170
export const mockDatabaseService = jest . fn ( ( ) => ( {
102
171
get : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
103
172
create : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
@@ -107,3 +176,32 @@ export const mockDatabaseService = jest.fn(() => ({
107
176
export const mockDatabaseConnectionService = jest . fn ( ( ) => ( {
108
177
getOrCreateClient : jest . fn ( ) . mockResolvedValue ( mockIORedisClient ) ,
109
178
} ) ) ;
179
+
180
+ export const mockDatabaseInfoProvider = jest . fn ( ( ) => ( {
181
+ isCluster : jest . fn ( ) ,
182
+ isSentinel : jest . fn ( ) ,
183
+ determineDatabaseModules : jest . fn ( ) ,
184
+ determineSentinelMasterGroups : jest . fn ( ) . mockReturnValue ( [ mockSentinelMasterDto ] ) ,
185
+ determineClusterNodes : jest . fn ( ) . mockResolvedValue ( mockClusterNodes ) ,
186
+ getRedisGeneralInfo : jest . fn ( ) . mockResolvedValueOnce ( mockRedisGeneralInfo ) ,
187
+ } ) ) ;
188
+
189
+ export const mockDatabaseOverviewProvider = jest . fn ( ( ) => ( {
190
+ getOverview : jest . fn ( ) . mockResolvedValue ( mockDatabaseOverview ) ,
191
+ } ) ) ;
192
+
193
+ export const mockDatabaseFactory = jest . fn ( ( ) => ( {
194
+ createDatabaseModel : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
195
+ createStandaloneDatabaseModel : jest . fn ( ) . mockResolvedValue ( mockDatabase ) ,
196
+ createClusterDatabaseModel : jest . fn ( ) . mockResolvedValue ( mockClusterDatabaseWithTlsAuth ) ,
197
+ createSentinelDatabaseModel : jest . fn ( ) . mockResolvedValue ( mockSentinelDatabaseWithTlsAuth ) ,
198
+ } ) ) ;
199
+
200
+ export const mockDatabaseAnalytics = jest . fn ( ( ) => ( {
201
+ sendInstanceListReceivedEvent : jest . fn ( ) ,
202
+ sendConnectionFailedEvent : jest . fn ( ) ,
203
+ sendInstanceAddedEvent : jest . fn ( ) ,
204
+ sendInstanceAddFailedEvent : jest . fn ( ) ,
205
+ sendInstanceEditedEvent : jest . fn ( ) ,
206
+ sendInstanceDeletedEvent : jest . fn ( ) ,
207
+ } ) ) ;
0 commit comments