-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
39 lines (31 loc) · 1.03 KB
/
index.test.js
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
const principal = { principal: 'username', credentials: 'password' };
let client;
beforeEach(() => {
client = require('./index')({
baseUrl: "http://localhost:8080",
});
});
test('client.authorize() returns a promise', () => {
expect(client.authorize(principal)).toBeInstanceOf(Promise);
});
test('client.authorize() success', async () => {
expect((await client.authorize(principal)).authorized()).toBe(true);
});
test('client.authorize() failure', async () => {
const badPrincipal = { principal: 'bad', credentials: 'bad' };
const session = await client.authorize(badPrincipal);
expect(session.authorized()).toBe(false);
let present = false;
try {
session.token();
session.refreshToken();
present = true;
} catch (e) {
}
expect(present).toBe(false);
});
test('client.authorize() token details', async () => {
const result = await client.authorize(principal);
expect(result.token()).not.toBe(undefined);
expect(result.refreshToken()).not.toBe(undefined);
});