11import { afterAll , afterEach , describe , expect , it , vi } from 'vitest'
2- import { authn , authSession , solidLogicSingleton } from 'solid-logic'
32import * as testLogin from '../../../src/login/login'
43
54describe ( 'ensureLoggedIn' , ( ) => {
@@ -20,24 +19,25 @@ describe('getUserRoles', () => {
2019 } )
2120
2221 it ( 'returns [] and does not load preferences when current user is missing' , async ( ) => {
23- vi . spyOn ( authSession , 'info' , 'get' ) . mockReturnValue ( {
22+ vi . resetModules ( )
23+
24+ const { authn, authSession, solidLogicSingleton } = await import ( 'solid-logic' )
25+
26+ authSession . info = {
2427 isLoggedIn : true ,
25- webId : 'https://alice.example.com/profile/card#me' ,
26- sessionId : 'test-session'
27- } )
28+ webId : 'https://alice.example.com/profile/card#me'
29+ }
2830
29- const currentUserSpy = vi
30- . spyOn ( authn , 'currentUser' )
31- . mockReturnValue ( null )
32- const loadPreferencesSpy = vi . spyOn (
33- solidLogicSingleton . profile ,
34- 'loadPreferences'
35- )
31+ vi . spyOn ( authn , 'checkUser' ) . mockResolvedValue ( null )
3632
37- const roles = await testLogin . getUserRoles ( )
33+ const currentUserSpy = vi . spyOn ( authn , 'currentUser' ) . mockReturnValue ( null )
34+ const loadPreferencesSpy = vi . spyOn ( solidLogicSingleton . profile , 'loadPreferences' )
35+
36+ const { getUserRoles } = await import ( '../../../src/login/login' )
37+ const roles = await getUserRoles ( )
3838
39- expect ( currentUserSpy ) . toHaveBeenCalled ( )
4039 expect ( roles ) . toEqual ( [ ] )
40+ expect ( currentUserSpy ) . toHaveBeenCalled ( )
4141 expect ( loadPreferencesSpy ) . not . toHaveBeenCalled ( )
4242 } )
4343} )
0 commit comments