-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathlogin.test.ts
More file actions
44 lines (37 loc) · 1.15 KB
/
login.test.ts
File metadata and controls
44 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as testLogin from '../../../src/login/login'
describe('ensureLoggedIn', () => {
afterAll(() => {
jest.restoreAllMocks()
})
it('exists', () => {
expect(testLogin.ensureLoggedIn).toBeInstanceOf(Function)
})
it('runs', () => {
expect(testLogin.ensureLoggedIn({})).toBeInstanceOf(Object)
})
})
describe('getUserRoles', () => {
afterEach(() => {
jest.restoreAllMocks()
jest.resetModules()
})
it('returns [] and does not load preferences when current user is missing', async () => {
const solidLogic = require('solid-logic')
solidLogic.authSession.info = {
isLoggedIn: true,
webId: 'https://alice.example.com/profile/card#me'
}
const currentUserSpy = jest
.spyOn(solidLogic.authn, 'currentUser')
.mockReturnValue(null)
const loadPreferencesSpy = jest.spyOn(
solidLogic.solidLogicSingleton.profile,
'loadPreferences'
)
const loginModule = require('../../../src/login/login')
const roles = await loginModule.getUserRoles()
expect(currentUserSpy).toHaveBeenCalled()
expect(roles).toEqual([])
expect(loadPreferencesSpy).not.toHaveBeenCalled()
})
})