-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCedarlingClient.test.ts
More file actions
46 lines (40 loc) · 1.51 KB
/
CedarlingClient.test.ts
File metadata and controls
46 lines (40 loc) · 1.51 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
import { cedarlingClient } from '@/cedarling/client/CedarlingClient'
import type { TokenAuthorizationRequest } from '@/cedarling'
// The WASM module is mocked via __mocks__/@janssenproject/cedarling_wasm.ts
describe('cedarlingClient', () => {
it('exports initialize and token_authorize methods', () => {
expect(typeof cedarlingClient.initialize).toBe('function')
expect(typeof cedarlingClient.token_authorize).toBe('function')
})
describe('initialize', () => {
it('initializes without error', async () => {
await expect(cedarlingClient.initialize({})).resolves.toBeUndefined()
})
it('does not re-initialize when already initialized', async () => {
await cedarlingClient.initialize({})
await expect(cedarlingClient.initialize({})).resolves.toBeUndefined()
})
})
describe('token_authorize', () => {
const request: TokenAuthorizationRequest = {
tokens: {
access_token: 'test-access-token',
id_token: 'test-id-token',
userinfo_token: 'test-userinfo-token',
},
action: 'Gluu::Flex::AdminUI::Action::"read"',
resource: {
cedar_entity_mapping: {
entity_type: 'Gluu::Flex::AdminUI::Resources::Features',
id: 'Dashboard',
},
},
context: {},
}
it('returns authorization response after initialization', async () => {
await cedarlingClient.initialize({})
const response = await cedarlingClient.token_authorize(request)
expect(response).toHaveProperty('decision')
})
})
})