@@ -11,6 +11,38 @@ jest.mock('@/services/timeline', () => ({
1111 getFollowingFeed : jest . fn ( ) ,
1212} ) ) ;
1313
14+ // Mock the userStore
15+ jest . mock ( '@/stores/userStore' , ( ) => ( {
16+ useUserStore : jest . fn ( ( selector ) => {
17+ const state = {
18+ user : {
19+ username : 'testuser' ,
20+ displayName : 'Test User' ,
21+ bio : null ,
22+ bioEntities : null ,
23+ avatarUrl : null ,
24+ bannerUrl : null ,
25+ location : null ,
26+ websiteUrl : null ,
27+ birthDate : null ,
28+ joinedAt : null ,
29+ relationship : {
30+ blocking : false ,
31+ blockedBy : false ,
32+ muted : false ,
33+ following : false ,
34+ follower : false ,
35+ } ,
36+ followingCount : 0 ,
37+ followersCount : 0 ,
38+ mutualsCount : 0 ,
39+ mutualNames : [ ] ,
40+ } ,
41+ } ;
42+ return selector ? selector ( state ) : state ;
43+ } ) ,
44+ } ) ) ;
45+
1446const mockGetFollowingFeed = timelineService . getFollowingFeed as jest . MockedFunction <
1547 typeof timelineService . getFollowingFeed
1648> ;
@@ -329,4 +361,45 @@ describe('useFollowingFeed', () => {
329361 expect ( allData ) . toHaveLength ( 2 ) ;
330362 expect ( allData ) . toEqual ( mockTweets ) ;
331363 } ) ;
364+
365+ it ( 'should include username in query key for account-specific caching' , async ( ) => {
366+ mockGetFollowingFeed . mockResolvedValueOnce ( {
367+ success : true ,
368+ message : 'Success' ,
369+ data : mockTweets ,
370+ pagination : { cursor : null , nextCursor : null , hasNextPage : false } ,
371+ } ) ;
372+
373+ const queryClient = new QueryClient ( {
374+ defaultOptions : {
375+ queries : {
376+ retry : false ,
377+ gcTime : 0 ,
378+ } ,
379+ } ,
380+ } ) ;
381+
382+ const Wrapper = ( { children } : { children : ReactNode } ) => (
383+ < QueryClientProvider client = { queryClient } > { children } </ QueryClientProvider >
384+ ) ;
385+
386+ const { result } = renderHook ( ( ) => useFollowingFeed ( ) , {
387+ wrapper : Wrapper ,
388+ } ) ;
389+
390+ await waitFor ( ( ) => {
391+ expect ( result . current . isSuccess ) . toBe ( true ) ;
392+ } ) ;
393+
394+ // Verify the query was created with the correct key including username
395+ const queries = queryClient . getQueryCache ( ) . getAll ( ) ;
396+ expect ( queries . length ) . toBeGreaterThan ( 0 ) ;
397+
398+ const followingQuery = queries . find (
399+ ( q ) => Array . isArray ( q . queryKey ) && q . queryKey [ 0 ] === 'following-feed'
400+ ) ;
401+
402+ expect ( followingQuery ) . toBeDefined ( ) ;
403+ expect ( followingQuery ?. queryKey ) . toEqual ( [ 'following-feed' , 'testuser' ] ) ;
404+ } ) ;
332405} ) ;
0 commit comments