@@ -15,8 +15,8 @@ describe(compressionMiddleware.name, () => {
15
15
const mockBody = "body" ;
16
16
const mockConfig = {
17
17
bodyLengthChecker : jest . fn ( ) . mockReturnValue ( mockBody . length ) ,
18
- disableRequestCompression : false ,
19
- requestMinCompressionSizeBytes : 0 ,
18
+ disableRequestCompression : ( ) => Promise . resolve ( false ) ,
19
+ requestMinCompressionSizeBytes : ( ) => Promise . resolve ( 0 ) ,
20
20
} ;
21
21
const mockMiddlewareConfig = {
22
22
encodings : [ CompressionAlgorithm . GZIP ] ,
@@ -32,20 +32,23 @@ describe(compressionMiddleware.name, () => {
32
32
33
33
it ( "skips compression if it's not an HttpRequest" , async ( ) => {
34
34
const { isInstance } = HttpRequest ;
35
- ( isInstance as unknown as jest . Mock ) . mockReturnValue ( false ) ;
35
+ ( ( isInstance as unknown ) as jest . Mock ) . mockReturnValue ( false ) ;
36
36
await compressionMiddleware ( mockConfig , mockMiddlewareConfig ) ( mockNext , mockContext ) ( { ...mockArgs } as any ) ;
37
37
expect ( mockNext ) . toHaveBeenCalledWith ( mockArgs ) ;
38
38
} ) ;
39
39
40
40
describe ( "HttpRequest" , ( ) => {
41
41
beforeEach ( ( ) => {
42
42
const { isInstance } = HttpRequest ;
43
- ( isInstance as unknown as jest . Mock ) . mockReturnValue ( true ) ;
43
+ ( ( isInstance as unknown ) as jest . Mock ) . mockReturnValue ( true ) ;
44
44
( isStreaming as jest . Mock ) . mockReturnValue ( false ) ;
45
45
} ) ;
46
46
47
47
it ( "skips compression if disabled" , async ( ) => {
48
- await compressionMiddleware ( { ...mockConfig , disableRequestCompression : true } , mockMiddlewareConfig ) (
48
+ await compressionMiddleware (
49
+ { ...mockConfig , disableRequestCompression : ( ) => Promise . resolve ( true ) } ,
50
+ mockMiddlewareConfig
51
+ ) (
49
52
mockNext ,
50
53
mockContext
51
54
) ( { ...mockArgs } as any ) ;
@@ -107,7 +110,7 @@ describe(compressionMiddleware.name, () => {
107
110
describe ( "not streaming" , ( ) => {
108
111
it ( "skips compression if body is smaller than min size" , async ( ) => {
109
112
await compressionMiddleware (
110
- { ...mockConfig , requestMinCompressionSizeBytes : mockBody . length + 1 } ,
113
+ { ...mockConfig , requestMinCompressionSizeBytes : ( ) => Promise . resolve ( mockBody . length + 1 ) } ,
111
114
mockMiddlewareConfig
112
115
) (
113
116
mockNext ,
0 commit comments