Skip to content

Commit ef63626

Browse files
authored
Merge pull request #803 from NoelDeMartin/login-tests
Fix login tests
2 parents 9301716 + 7a72278 commit ef63626

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint-fix": "eslint --fix",
4444
"typecheck": "tsc --noEmit",
4545
"typecheck-test": "tsc --noEmit -p tsconfig.test.json",
46-
"test": "vitest run",
46+
"test": "npm run typecheck-test && vitest run",
4747
"test-coverage": "vitest run --coverage",
4848
"test-debug": "vitest --inspect-brk --no-file-parallelism",
4949
"doc": "typedoc --out ./docs/api/ ./src/ --excludeInternal",

test/unit/login/login.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
2-
import { authn, authSession, solidLogicSingleton } from 'solid-logic'
32
import * as testLogin from '../../../src/login/login'
43

54
describe('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

Comments
 (0)