@@ -232,6 +232,46 @@ describe('getWorkspaceCreationPolicy', () => {
232232 expect ( mockGetHighestPrioritySubscription ) . not . toHaveBeenCalled ( )
233233 } )
234234
235+ it ( 'keeps platform admins in org context when the org lacks a team plan' , async ( ) => {
236+ mockGetUserOrganization . mockResolvedValueOnce ( {
237+ organizationId : 'org-1' ,
238+ role : 'admin' ,
239+ memberId : 'member-1' ,
240+ } )
241+ mockGetOrganizationSubscription . mockResolvedValueOnce ( null )
242+ mockDbResults . value = [ [ { role : 'admin' } ] , [ { userId : 'owner-1' } ] ]
243+
244+ const result = await getWorkspaceCreationPolicy ( {
245+ userId : 'admin-user' ,
246+ activeOrganizationId : 'org-1' ,
247+ } )
248+
249+ expect ( result . canCreate ) . toBe ( true )
250+ expect ( result . workspaceMode ) . toBe ( WORKSPACE_MODE . ORGANIZATION )
251+ expect ( result . organizationId ) . toBe ( 'org-1' )
252+ expect ( result . billedAccountUserId ) . toBe ( 'owner-1' )
253+ expect ( mockGetHighestPrioritySubscription ) . not . toHaveBeenCalled ( )
254+ } )
255+
256+ it ( 'blocks platform admins who are only org members from creating org workspaces' , async ( ) => {
257+ mockGetUserOrganization . mockResolvedValueOnce ( {
258+ organizationId : 'org-1' ,
259+ role : 'member' ,
260+ memberId : 'member-1' ,
261+ } )
262+ mockGetOrganizationSubscription . mockResolvedValueOnce ( null )
263+ mockDbResults . value = [ [ { role : 'admin' } ] , [ { value : 0 } ] ]
264+
265+ const result = await getWorkspaceCreationPolicy ( {
266+ userId : 'admin-user' ,
267+ activeOrganizationId : 'org-1' ,
268+ } )
269+
270+ expect ( result . canCreate ) . toBe ( true )
271+ expect ( result . workspaceMode ) . toBe ( WORKSPACE_MODE . PERSONAL )
272+ expect ( result . organizationId ) . toBeNull ( )
273+ } )
274+
235275 it ( 'still enforces plan limits for non-admin users' , async ( ) => {
236276 mockDbResults . value = [ [ { role : 'user' } ] , [ { value : 1 } ] ]
237277
0 commit comments