@@ -16,13 +16,15 @@ const {
1616 mockIsCloud,
1717 mockAuthStoreInitialized,
1818 mockGetBillingStatus,
19+ mockActiveWorkspaceId,
1920 mockSetWorkspaceBillingRail,
2021 mockLocalStorage
2122} = vi . hoisted ( ( ) => ( {
2223 mockIsLoggedIn : { value : false } ,
2324 mockIsCloud : { value : true } ,
2425 mockAuthStoreInitialized : { value : true } ,
2526 mockGetBillingStatus : vi . fn ( ) ,
27+ mockActiveWorkspaceId : { value : 'workspace-123' as string | null } ,
2628 mockSetWorkspaceBillingRail : vi . fn ( ) ,
2729 mockReportError : vi . fn ( ) ,
2830 mockAccessBillingPortal : vi . fn ( ) ,
@@ -146,7 +148,9 @@ vi.mock('@/platform/workspace/api/workspaceApi', () => ({
146148
147149vi . mock ( '@/platform/workspace/stores/teamWorkspaceStore' , ( ) => ( {
148150 useTeamWorkspaceStore : ( ) => ( {
149- activeWorkspaceId : 'workspace-123' ,
151+ get activeWorkspaceId ( ) {
152+ return mockActiveWorkspaceId . value
153+ } ,
150154 setWorkspaceBillingRail : mockSetWorkspaceBillingRail
151155 } )
152156} ) )
@@ -198,6 +202,7 @@ describe('useSubscription', () => {
198202 mockUserId . value = 'user-123'
199203 mockIsCloud . value = true
200204 mockAuthStoreInitialized . value = true
205+ mockActiveWorkspaceId . value = 'workspace-123'
201206 mockGetBillingStatus . mockResolvedValue ( {
202207 is_active : false ,
203208 has_funds : false ,
@@ -352,6 +357,31 @@ describe('useSubscription', () => {
352357 )
353358 } )
354359
360+ it ( 'does not apply status after the active workspace changes' , async ( ) => {
361+ let resolveStatus : ( value : {
362+ is_active : boolean
363+ has_funds : boolean
364+ billing_rail : 'stripe'
365+ } ) => void = ( ) => { }
366+ mockGetBillingStatus . mockReturnValue (
367+ new Promise ( ( resolve ) => {
368+ resolveStatus = resolve
369+ } )
370+ )
371+
372+ const { fetchStatus } = useSubscriptionWithScope ( )
373+ const statusRequest = fetchStatus ( )
374+ mockActiveWorkspaceId . value = 'workspace-456'
375+ resolveStatus ( {
376+ is_active : true ,
377+ has_funds : true ,
378+ billing_rail : 'stripe'
379+ } )
380+ await statusRequest
381+
382+ expect ( mockSetWorkspaceBillingRail ) . not . toHaveBeenCalled ( )
383+ } )
384+
355385 it ( 'coalesces concurrent callers into one fetch' , async ( ) => {
356386 let resolveStatus : ( value : {
357387 is_active : boolean
0 commit comments