1
1
import { DatabaseImportResponse , DatabaseImportStatus } from 'src/modules/database-import/dto/database-import.response' ;
2
2
import { BadRequestException , ForbiddenException } from '@nestjs/common' ;
3
- import { mockDatabase } from 'src/__mocks__/databases' ;
3
+ import { mockDatabase , mockSentinelDatabaseWithTlsAuth } from 'src/__mocks__/databases' ;
4
4
import { ValidationException } from 'src/common/exceptions' ;
5
+ import { mockCaCertificate , mockClientCertificate } from 'src/__mocks__/certificates' ;
6
+ import {
7
+ InvalidCaCertificateBodyException , InvalidCertificateNameException ,
8
+ } from 'src/modules/database-import/exceptions' ;
5
9
6
- export const mockDatabasesToImportArray = new Array ( 10 ) . fill ( mockDatabase ) ;
10
+ export const mockDatabasesToImportArray = new Array ( 10 ) . fill ( mockSentinelDatabaseWithTlsAuth ) ;
7
11
8
12
export const mockDatabaseImportFile = {
9
13
originalname : 'filename.json' ,
@@ -27,13 +31,28 @@ export const mockDatabaseImportResultFail = {
27
31
errors : [ new BadRequestException ( ) ] ,
28
32
} ;
29
33
34
+ export const mockDatabaseImportResultPartial = {
35
+ index : 0 ,
36
+ status : DatabaseImportStatus . Partial ,
37
+ host : mockDatabase . host ,
38
+ port : mockDatabase . port ,
39
+ errors : [ new InvalidCaCertificateBodyException ( ) ] ,
40
+ } ;
41
+
30
42
export const mockDatabaseImportResponse = Object . assign ( new DatabaseImportResponse ( ) , {
31
43
total : 10 ,
32
- success : ( new Array ( 7 ) . fill ( mockDatabaseImportResultSuccess ) ) . map ( ( v , index ) => ( {
44
+ success : ( new Array ( 5 ) . fill ( mockDatabaseImportResultSuccess ) ) . map ( ( v , index ) => ( {
33
45
...v ,
46
+ index : index + 5 ,
47
+ } ) ) ,
48
+ partial : [
49
+ [ new InvalidCaCertificateBodyException ( ) , new InvalidCertificateNameException ( ) ] ,
50
+ [ new InvalidCertificateNameException ( ) ] ,
51
+ ] . map ( ( errors , index ) => ( {
52
+ ...mockDatabaseImportResultPartial ,
34
53
index : index + 3 ,
54
+ errors,
35
55
} ) ) ,
36
- partial : [ ] ,
37
56
fail : [
38
57
new ValidationException ( 'Bad request' ) ,
39
58
new BadRequestException ( ) ,
@@ -45,8 +64,9 @@ export const mockDatabaseImportResponse = Object.assign(new DatabaseImportRespon
45
64
} ) ) ,
46
65
} ) ;
47
66
48
- export const mockDatabaseImportParseFailedAnalyticsPayload = {
49
-
67
+ export const mockDatabaseImportPartialAnalyticsPayload = {
68
+ partially : mockDatabaseImportResponse . partial . length ,
69
+ errors : [ 'InvalidCaCertificateBodyException' , 'InvalidCertificateNameException' ] ,
50
70
} ;
51
71
52
72
export const mockDatabaseImportFailedAnalyticsPayload = {
@@ -63,6 +83,7 @@ export const mockDatabaseImportAnalytics = jest.fn(() => ({
63
83
sendImportFailed : jest . fn ( ) ,
64
84
} ) ) ;
65
85
66
- export const mockCertificateImportService = jest . fn ( ( ) => {
67
-
68
- } ) ;
86
+ export const mockCertificateImportService = jest . fn ( ( ) => ( {
87
+ processCaCertificate : jest . fn ( ) . mockResolvedValue ( mockCaCertificate ) ,
88
+ processClientCertificate : jest . fn ( ) . mockResolvedValue ( mockClientCertificate ) ,
89
+ } ) ) ;
0 commit comments