@@ -33,30 +33,25 @@ describe('useDataExport', () => {
3333 } ) ;
3434
3535 it ( 'should display default error message on failure when none is provided' , async ( ) => {
36- const inProgressCallback = jest . fn ( ) ;
37-
3836 MockApiClient . addMockResponse ( {
3937 ...requestBase ,
4038 statusCode : 400 ,
4139 } ) ;
4240
43- const { result} = renderHookWithProviders ( ( ) => useDataExport ( { inProgressCallback } ) , {
41+ const { result} = renderHookWithProviders ( ( ) => useDataExport ( ) , {
4442 organization : mockAuthorizedOrg ,
4543 } ) ;
4644
47- await result . current ( { ...mockPayload } ) ;
45+ result . current . mutate ( { ...mockPayload } ) ;
4846
4947 await waitFor ( ( ) => {
5048 expect ( addErrorMessage ) . toHaveBeenCalledWith (
5149 "We tried our hardest, but we couldn't export your data. Try waiting a minute then giving it another go."
5250 ) ;
5351 } ) ;
54-
55- expect ( inProgressCallback ) . toHaveBeenCalledWith ( false ) ;
5652 } ) ;
5753
5854 it ( 'should display the provided error message on failure when one is provided' , async ( ) => {
59- const inProgressCallback = jest . fn ( ) ;
6055 const detail = 'Oh no!' ;
6156
6257 MockApiClient . addMockResponse ( {
@@ -65,34 +60,15 @@ describe('useDataExport', () => {
6560 body : { detail} ,
6661 } ) ;
6762
68- const { result} = renderHookWithProviders ( ( ) => useDataExport ( { inProgressCallback } ) , {
63+ const { result} = renderHookWithProviders ( ( ) => useDataExport ( ) , {
6964 organization : mockAuthorizedOrg ,
7065 } ) ;
7166
72- await result . current ( { ...mockPayload } ) ;
67+ result . current . mutate ( { ...mockPayload } ) ;
7368
7469 await waitFor ( ( ) => {
7570 expect ( addErrorMessage ) . toHaveBeenCalledWith ( detail ) ;
7671 } ) ;
77-
78- expect ( inProgressCallback ) . toHaveBeenCalledWith ( false ) ;
79- } ) ;
80-
81- it ( 'should not add an error message when unmountedRef is already true' , async ( ) => {
82- MockApiClient . addMockResponse ( {
83- ...requestBase ,
84- statusCode : 400 ,
85- } ) ;
86-
87- const unmountedRef = { current : true } ;
88-
89- const { result} = renderHookWithProviders ( ( ) => useDataExport ( { unmountedRef} ) , {
90- organization : mockAuthorizedOrg ,
91- } ) ;
92-
93- await result . current ( { ...mockPayload } ) ;
94-
95- expect ( addErrorMessage ) . not . toHaveBeenCalled ( ) ;
9672 } ) ;
9773
9874 it ( 'should notify when export is queued (201, no fileName)' , async ( ) => {
@@ -106,7 +82,7 @@ describe('useDataExport', () => {
10682 organization : mockAuthorizedOrg ,
10783 } ) ;
10884
109- await result . current ( { ...mockPayload } ) ;
85+ result . current . mutate ( { ...mockPayload } ) ;
11086
11187 await waitFor ( ( ) => {
11288 expect ( addSuccessMessage ) . toHaveBeenCalledWith (
@@ -126,7 +102,7 @@ describe('useDataExport', () => {
126102 organization : mockAuthorizedOrg ,
127103 } ) ;
128104
129- await result . current ( { ...mockPayload } ) ;
105+ result . current . mutate ( { ...mockPayload } ) ;
130106
131107 await waitFor ( ( ) => {
132108 expect ( addSuccessMessage ) . toHaveBeenCalledWith (
@@ -146,7 +122,7 @@ describe('useDataExport', () => {
146122 organization : mockAuthorizedOrg ,
147123 } ) ;
148124
149- await result . current ( { format : 'csv' , ...mockPayload } ) ;
125+ result . current . mutate ( { format : 'csv' , ...mockPayload } ) ;
150126
151127 await waitFor ( ( ) => {
152128 expect ( downloadFromHref ) . toHaveBeenCalledWith (
@@ -171,41 +147,43 @@ describe('useDataExport', () => {
171147 organization : mockAuthorizedOrg ,
172148 } ) ;
173149
174- await result . current ( {
150+ result . current . mutate ( {
175151 format : 'csv' ,
176152 queryInfo : mockPayload . queryInfo ,
177153 queryType : mockPayload . queryType ,
178154 limit : 10_000 ,
179155 } ) ;
180156
181- expect ( exportMock ) . toHaveBeenCalledWith ( '/organizations/org-slug/data-export/' , {
182- data : {
183- format : 'csv' ,
184- query_type : mockPayload . queryType ,
185- query_info : mockPayload . queryInfo ,
186- limit : 10_000 ,
187- } ,
188- error : expect . any ( Function ) ,
189- method : 'POST' ,
190- success : expect . any ( Function ) ,
157+ await waitFor ( ( ) => {
158+ expect ( exportMock ) . toHaveBeenCalledWith ( '/organizations/org-slug/data-export/' , {
159+ data : {
160+ format : 'csv' ,
161+ query_type : mockPayload . queryType ,
162+ query_info : mockPayload . queryInfo ,
163+ limit : 10_000 ,
164+ } ,
165+ error : expect . any ( Function ) ,
166+ method : 'POST' ,
167+ success : expect . any ( Function ) ,
168+ } ) ;
191169 } ) ;
192170 } ) ;
193171
194- it ( 'should call inProgressCallback with true when an export starts' , async ( ) => {
195- const inProgressCallback = jest . fn ( ) ;
196-
172+ it ( 'should settle into a success state once an export is queued' , async ( ) => {
197173 MockApiClient . addMockResponse ( {
198174 ...requestBase ,
199175 statusCode : 201 ,
200176 body : { id : 721 } ,
201177 } ) ;
202178
203- const { result} = renderHookWithProviders ( ( ) => useDataExport ( { inProgressCallback } ) , {
179+ const { result} = renderHookWithProviders ( ( ) => useDataExport ( ) , {
204180 organization : mockAuthorizedOrg ,
205181 } ) ;
206182
207- const exportPromise = result . current ( { ...mockPayload } ) ;
208- expect ( inProgressCallback ) . toHaveBeenCalledWith ( true ) ;
209- await exportPromise ;
183+ result . current . mutate ( { ...mockPayload } ) ;
184+
185+ await waitFor ( ( ) => {
186+ expect ( result . current . isSuccess ) . toBe ( true ) ;
187+ } ) ;
210188 } ) ;
211189} ) ;
0 commit comments