-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcerts.test.ts
More file actions
30 lines (27 loc) · 862 Bytes
/
certs.test.ts
File metadata and controls
30 lines (27 loc) · 862 Bytes
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
import mockAxios from 'axios'
import { Tokens, Certs } from '../src'
import { makeToken } from './utils'
// endpoints that have oauth/ in path don't include /{apiVersion}/
const apiUrl = `https://api.ordercloud.io`
const validToken = makeToken()
const mockKid = 'x6sA-GfTGEWUp5OWFbhmmg'
beforeEach(() => {
jest.clearAllMocks() // cleans up any tracked calls before the next test
Tokens.RemoveAccessToken()
})
test('can get cert', async () => {
Tokens.SetAccessToken(validToken)
await Certs.GetPublicKey(mockKid)
expect(mockAxios.get).toHaveBeenCalledTimes(1)
expect(mockAxios.get).toHaveBeenCalledWith(
`${apiUrl}/oauth/certs/${mockKid}`,
{
paramsSerializer: expect.any(Object),
timeout: 60000,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${validToken}`,
},
}
)
})