-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwk.test.ts
35 lines (34 loc) · 1.02 KB
/
jwk.test.ts
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
import { JWK } from "./jwk"
import { Problem } from "../core"
describe("JWK", () => {
describe("fetch", () => {
it("returns a JWKS", async () => {
const issuer = "http://localhost"
const jwks = jest.fn()
const json = jest.fn(() => jwks)
const fetch = jest.fn(() => {
return { ok: true, json }
})
Object.assign(global, {
fetch,
})
const result = await JWK.fetch(issuer)
expect(result).toBe(jwks)
expect(fetch).toHaveBeenCalledWith(expect.stringContaining(issuer))
expect(json).toHaveBeenCalled()
})
it("throws an error when response not ok", async () => {
const issuer = "http://localhost"
const json = jest.fn()
const fetch = jest.fn(() => {
return { ok: false, json }
})
Object.assign(global, {
fetch,
})
await expect(JWK.fetch(issuer)).rejects.toThrow(Problem)
expect(fetch).toHaveBeenCalledWith(expect.stringContaining(issuer))
expect(json).not.toHaveBeenCalled()
})
})
})