1
- import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
1
+ import {
2
+ QueryClientProvider as QueryClientProviderV5 ,
3
+ QueryClient as QueryClientV5 ,
4
+ useQuery as useQueryV5 ,
5
+ } from '@tanstack/react-queryV5'
2
6
import { renderHook , waitFor } from '@testing-library/react'
3
7
import { graphql , HttpResponse } from 'msw'
4
8
import { setupServer } from 'msw/node'
@@ -7,18 +11,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
7
11
8
12
import { mapEdges } from 'shared/utils/graphql'
9
13
10
- import { Session , UserToken , useSessions } from './useSessions'
11
-
12
- const queryClient = new QueryClient ( {
13
- defaultOptions : { queries : { retry : false } } ,
14
- } )
15
- const wrapper : React . FC < React . PropsWithChildren > = ( { children } ) => (
16
- < MemoryRouter initialEntries = { [ '/gh' ] } >
17
- < Route path = "/:provider" >
18
- < QueryClientProvider client = { queryClient } > { children } </ QueryClientProvider >
19
- </ Route >
20
- </ MemoryRouter >
21
- )
14
+ import { Session , SessionsQueryOpts , UserToken } from './SessionsQueryOpts'
22
15
23
16
const provider = 'gh'
24
17
@@ -71,14 +64,25 @@ const tokens: { edges: { node: UserToken }[] } = {
71
64
] ,
72
65
}
73
66
67
+ const queryClientV5 = new QueryClientV5 ( {
68
+ defaultOptions : { queries : { retry : false } } ,
69
+ } )
70
+ const wrapper : React . FC < React . PropsWithChildren > = ( { children } ) => (
71
+ < QueryClientProviderV5 client = { queryClientV5 } >
72
+ < MemoryRouter initialEntries = { [ '/gh' ] } >
73
+ < Route path = "/:provider" > { children } </ Route >
74
+ </ MemoryRouter >
75
+ </ QueryClientProviderV5 >
76
+ )
77
+
74
78
const server = setupServer ( )
75
79
beforeAll ( ( ) => {
76
80
server . listen ( )
77
81
} )
78
82
79
83
beforeEach ( ( ) => {
80
84
server . resetHandlers ( )
81
- queryClient . clear ( )
85
+ queryClientV5 . clear ( )
82
86
} )
83
87
84
88
afterAll ( ( ) => {
@@ -119,14 +123,12 @@ describe('useSessions', () => {
119
123
}
120
124
121
125
describe ( 'when called and response parsing fails' , ( ) => {
122
- beforeEach ( ( ) => {
123
- setup ( { isUnsuccessfulParseError : true } )
124
- } )
125
-
126
126
it ( 'throws a 404' , async ( ) => {
127
- const { result } = renderHook ( ( ) => useSessions ( { provider } ) , {
128
- wrapper,
129
- } )
127
+ setup ( { isUnsuccessfulParseError : true } )
128
+ const { result } = renderHook (
129
+ ( ) => useQueryV5 ( SessionsQueryOpts ( { provider } ) ) ,
130
+ { wrapper }
131
+ )
130
132
131
133
await waitFor ( ( ) => expect ( result . current . isError ) . toBeTruthy ( ) )
132
134
await waitFor ( ( ) =>
@@ -141,43 +143,32 @@ describe('useSessions', () => {
141
143
} )
142
144
143
145
describe ( 'when called and user is unauthenticated' , ( ) => {
144
- beforeEach ( ( ) => {
145
- setup ( {
146
- dataReturned : {
147
- me : null ,
148
- } ,
149
- } )
150
- } )
151
-
152
146
it ( 'returns null' , async ( ) => {
153
- const { result } = renderHook ( ( ) => useSessions ( { provider } ) , {
154
- wrapper,
155
- } )
147
+ setup ( { dataReturned : { me : null } } )
148
+ const { result } = renderHook (
149
+ ( ) => useQueryV5 ( SessionsQueryOpts ( { provider } ) ) ,
150
+ { wrapper }
151
+ )
156
152
157
153
await waitFor ( ( ) => expect ( result . current . data ) . toEqual ( null ) )
158
154
} )
159
155
} )
160
156
161
157
describe ( 'when called and user is authenticated' , ( ) => {
162
- beforeEach ( ( ) => {
158
+ it ( 'returns sessions' , async ( ) => {
163
159
setup ( {
164
160
dataReturned : {
165
161
me : {
166
- sessions : {
167
- edges : [ ...sessions . edges ] ,
168
- } ,
169
- tokens : {
170
- edges : [ ...tokens . edges ] ,
171
- } ,
162
+ sessions : { edges : [ ...sessions . edges ] } ,
163
+ tokens : { edges : [ ...tokens . edges ] } ,
172
164
} ,
173
165
} ,
174
166
} )
175
- } )
176
167
177
- it ( 'returns sessions' , async ( ) => {
178
- const { result } = renderHook ( ( ) => useSessions ( { provider } ) , {
179
- wrapper,
180
- } )
168
+ const { result } = renderHook (
169
+ ( ) => useQueryV5 ( SessionsQueryOpts ( { provider } ) ) ,
170
+ { wrapper }
171
+ )
181
172
182
173
await waitFor ( ( ) =>
183
174
expect ( result . current . data ) . toEqual ( {
0 commit comments