This repository was archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathAuthService.test.ts
More file actions
48 lines (40 loc) · 1.33 KB
/
Copy pathAuthService.test.ts
File metadata and controls
48 lines (40 loc) · 1.33 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
45
46
47
48
import { AuthService, AuthTokens, AuthServiceProps } from './AuthService'
// import tokens from './__fixtures__/tokens.json'
const props: AuthServiceProps = {
clientId: 'testClientID',
clientSecret: undefined,
location,
contentType: undefined,
provider: 'http://oauth2provider/',
redirectUri: 'http://localhost/',
scopes: ['openid', 'profile']
}
const stubTokens: AuthTokens = {
accessToken: 'accessToken',
idToken: 'idToken',
refreshToken: 'refreshToken',
expiresIn: 3600,
tokenType: 'Bearer'
}
// const stubToken =
// '{"id_token":"id_token","access_token":"access_token","refresh_token":"refresh_token","expires_in":3600,"token_type":"Bearer"}'
const authService = new AuthService(props)
describe('AuthService', () => {
it('is truthy', () => {
expect(AuthService).toBeTruthy()
})
it('should add requestId to headers', () => {
const fakeFetch = jest.fn()
window.fetch = fakeFetch
const authorizationCode = 'authorizationCode'
authService.fetchToken(authorizationCode).then((tokens) => {
console.log(tokens)
expect(fakeFetch.mock.calls[0][1]).toHaveProperty('headers')
expect(fakeFetch.mock.calls[0][1].headers).toHaveProperty('requestId')
})
})
// it('it parses a token', () => {
// window.sessionStorage.setItem('auth', tokens)
// authService.getUser()
// })
})