1
1
import { batchedApiRequest } from "../src/actionBatchHelpers" ;
2
- import { apiRequest } from "../src/apiUtils" ;
2
+ import { ApiError , apiRequest } from "../src/apiUtils" ;
3
3
4
4
jest . mock ( "../src/apiUtils" ) ;
5
5
const mockedApiRequest = jest . mocked ( apiRequest ) as jest . Mock ;
@@ -55,9 +55,9 @@ describe("ActionBatchHelpers", () => {
55
55
56
56
try {
57
57
await batchedApiRequest ( orgId , actions , authOptions ) ;
58
- } catch ( err : any ) {
59
- expect ( err . errors ) . not . toBeNull ( ) ;
60
- expect ( err . errors ) . toEqual ( errorMsgs ) ;
58
+ } catch ( err ) {
59
+ expect ( ( err as ApiError ) . errors ) . not . toBeNull ( ) ;
60
+ expect ( ( err as ApiError ) . errors ) . toEqual ( errorMsgs ) ;
61
61
}
62
62
} ) ;
63
63
@@ -70,9 +70,9 @@ describe("ActionBatchHelpers", () => {
70
70
71
71
try {
72
72
await batchedApiRequest ( orgId , actions , authOptions ) ;
73
- } catch ( err : any ) {
74
- expect ( err . errors ) . not . toBeNull ( ) ;
75
- expect ( err . errors ) . toEqual ( errorMsgs ) ;
73
+ } catch ( err ) {
74
+ expect ( ( err as ApiError ) . errors ) . not . toBeNull ( ) ;
75
+ expect ( ( err as ApiError ) . errors ) . toEqual ( errorMsgs ) ;
76
76
}
77
77
} ) ;
78
78
@@ -90,11 +90,14 @@ describe("ActionBatchHelpers", () => {
90
90
91
91
try {
92
92
await batchedApiRequest ( orgId , actions , authOptions , { maxPollingTime : 1 } ) ;
93
- } catch ( err : any ) {
94
- expect ( err . errors ) . not . toBeNull ( ) ;
95
- expect ( err . errors ) . toEqual ( [ "Your updates have been submitted and are still pending. Try reloading the page." ] ) ;
93
+ } catch ( err ) {
94
+ expect ( ( err as ApiError ) . errors ) . not . toBeNull ( ) ;
95
+ expect ( ( err as ApiError ) . errors ) . toEqual ( [
96
+ "Your updates have been submitted and are still pending. Try reloading the page." ,
97
+ ] ) ;
96
98
}
97
99
} ) ;
100
+
98
101
it ( "polls the status when the initial status is pending" , async ( ) => {
99
102
mockedApiRequest . mockResolvedValue ( {
100
103
data : {
@@ -108,7 +111,7 @@ describe("ActionBatchHelpers", () => {
108
111
} ) ;
109
112
try {
110
113
await batchedApiRequest ( orgId , actions , authOptions , { maxPollingTime : 5 } ) ;
111
- } catch ( err : unknown ) {
114
+ } catch ( err ) {
112
115
expect ( mockedApiRequest . mock . calls . length ) . toBeGreaterThan ( 1 ) ;
113
116
expect ( mockedApiRequest . mock . calls ) . toContainEqual ( [ "GET" , "/api/v1/organizations/2/actionBatches/1234" ] ) ;
114
117
}
@@ -138,7 +141,7 @@ describe("ActionBatchHelpers", () => {
138
141
139
142
try {
140
143
await batchedApiRequest ( orgId , actions , authOptions , { maxPollingTime : 5 } ) ;
141
- } catch ( err : unknown ) {
144
+ } catch ( err ) {
142
145
expect ( mockedApiRequest . mock . calls . length ) . toEqual ( 2 ) ; // one for the initial POST, and one status update
143
146
expect ( err ) . toMatchObject ( { errors : [ "some error" ] } ) ;
144
147
}
0 commit comments