@@ -3,18 +3,16 @@ import * as redis from "./redis"
3
3
import { nanoid } from "../utils" ;
4
4
5
5
describe ( "redis" , ( ) => {
6
- test ( "should throw on missing results" , ( ) => {
7
- expect ( ( ) =>
8
- redis . checkRedisForResults ( "some-route" , "some-id" , - 1 , "some-result" , 1 )
9
- ) . toThrow (
10
- "result not found for route some-route with randomTestId some-id"
6
+ test ( "should throw on missing results" , { timeout : 15000 } , async ( ) => {
7
+ await expect ( redis . checkRedisForResults ( "some-route" , "some-id" , - 1 , "some-result" , 1 ) ) . rejects . toThrowError (
8
+ "result not found for route some-route with randomTestId some-id"
11
9
)
12
- } , { timeout : 15000 } )
10
+ } )
13
11
14
12
test ( "should throw when saving results without any increment" , ( ) => {
15
- expect ( ( ) =>
16
- redis . saveResultsWithoutContext ( "some-route" , "some-id" , "some-result" )
17
- ) . toThrow (
13
+ expect ( async ( ) =>
14
+ await redis . saveResultsWithoutContext ( "some-route" , "some-id" , "some-result" )
15
+ ) . rejects . toThrowError (
18
16
"callCount shouldn't be 0. It was 0 in test of the route 'some-route'"
19
17
)
20
18
} )
@@ -32,53 +30,54 @@ describe("redis", () => {
32
30
} )
33
31
34
32
test ( "should throw on mismatching result" , ( ) => {
35
- expect ( ( ) =>
36
- redis . checkRedisForResults ( route , randomId , 2 , "not-correct" )
37
- ) . toThrow (
33
+ expect ( async ( ) =>
34
+ await redis . checkRedisForResults ( route , randomId , 2 , "not-correct" )
35
+ ) . rejects . toThrowError (
38
36
`Unexpected value.\n\tReceived \"${ result } \"\n\tExpected \"not-correct\"`
39
37
)
40
38
} )
41
39
42
40
test ( "should throw on mismatching call count" , ( ) => {
43
- expect ( ( ) =>
44
- redis . checkRedisForResults ( route , randomId , 123 , result )
45
- ) . toThrow (
41
+ expect ( async ( ) =>
42
+ await redis . checkRedisForResults ( route , randomId , 123 , result )
43
+ ) . rejects . toThrowError (
46
44
`Unexpected value.\n\tReceived \"2\"\n\tExpected \"123\"`
47
45
)
48
46
} )
49
47
50
48
test ( "should not throw on correct results" , ( ) => {
51
- expect ( ( ) =>
52
- redis . checkRedisForResults ( route , randomId , 2 , result )
53
- ) . not . toThrow ( )
49
+ expect ( async ( ) =>
50
+ await redis . checkRedisForResults ( route , randomId , 2 , result )
51
+ ) . not . toThrowError ( )
54
52
} )
55
53
} )
56
54
57
- test ( "should override call count" , async ( ) => {
55
+ describe ( "override call count" , ( ) => {
56
+ test ( "should override call count" , async ( ) => {
57
+ const route = "override-route" ;
58
+ const randomId = `random-id-${ nanoid ( ) } ` ;
59
+ const result = `random-result-${ nanoid ( ) } ` ;
60
+ const override = - 3 ;
58
61
59
- const route = "override-route"
60
- const randomId = `random-id-${ nanoid ( ) } `
61
- const result = `random-result-${ nanoid ( ) } `
62
- const override = - 3
63
-
64
- await redis . increment ( route , randomId )
65
- await redis . increment ( route , randomId )
66
- await redis . increment ( route , randomId )
62
+ await redis . increment ( route , randomId ) ;
63
+ await redis . increment ( route , randomId ) ;
64
+ await redis . increment ( route , randomId ) ;
67
65
68
- await redis . saveResultsWithoutContext ( route , randomId , result , override )
66
+ await redis . saveResultsWithoutContext ( route , randomId , result , override ) ;
69
67
70
- expect ( ( ) =>
71
- redis . checkRedisForResults ( route , randomId , 3 , result )
72
- ) . toThrow (
73
- `Unexpected value.\n\tReceived \"-3\"\n\tExpected \"3\"`
74
- )
68
+ expect ( async ( ) =>
69
+ await redis . checkRedisForResults ( route , randomId , 3 , result )
70
+ ) . rejects . toThrowError (
71
+ `Unexpected value.\n\tReceived \"-3\"\n\tExpected \"3\"`
72
+ ) ;
73
+ } ) ;
75
74
76
75
test ( "should not throw on correct results" , ( ) => {
77
- expect ( ( ) =>
78
- redis . checkRedisForResults ( route , randomId , override , result )
79
- ) . not . toThrow ( )
80
- } )
81
- } )
76
+ expect ( async ( ) =>
77
+ await redis . checkRedisForResults ( "override- route" , `random-id- ${ nanoid ( ) } ` , - 3 , `random- result- ${ nanoid ( ) } ` )
78
+ ) . not . toThrowError ( ) ;
79
+ } ) ;
80
+ } ) ;
82
81
83
82
test ( "should fail if marked as failed" , async ( ) => {
84
83
@@ -93,7 +92,7 @@ describe("redis", () => {
93
92
94
93
// mark as failed and check
95
94
await redis . failWithoutContext ( route , randomId )
96
- expect ( redis . checkRedisForResults ( route , randomId , 1 , result ) ) . rejects . toThrow ( redis . FAILED_TEXT )
95
+ expect ( redis . checkRedisForResults ( route , randomId , 1 , result ) ) . rejects . toThrowError ( redis . FAILED_TEXT )
97
96
98
97
} )
99
98
} )
0 commit comments