forked from MrRefactoring/jira.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthenticationService.test.ts
47 lines (35 loc) · 1.4 KB
/
authenticationService.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
36
37
38
39
40
41
42
43
44
45
46
47
import { test } from 'vitest';
import type { Config } from '@jirajs';
import { getAuthenticationToken } from '@jirajs/services/authenticationService';
test('should return undefined when authentication does not used', async ({ expect }) => {
const authentication = undefined;
const token = await getAuthenticationToken(authentication);
expect(token).toBe(undefined);
});
test('should return Basic authentication token for password case', async ({ expect }) => {
const authentication: Config.Authentication = {
basic: {
username: 'test_username',
password: 'test_password',
},
};
const token = await getAuthenticationToken(authentication);
expect(token).toBe('Basic dGVzdF91c2VybmFtZTp0ZXN0X3Bhc3N3b3Jk');
});
test('should return Basic authentication token for apiToken case', async ({ expect }) => {
const authentication: Config.Authentication = {
basic: {
email: '[email protected]',
apiToken: 'test_apiToken',
},
};
const token = await getAuthenticationToken(authentication);
expect(token).toBe('Basic dGVzdF9lbWFpbEB0ZXN0LnF3ZTp0ZXN0X2FwaVRva2Vu');
});
test('should generate Bearer Header correctly for Personal Access Token', async ({ expect }) => {
const authentication: Config.Authentication = {
personalAccessToken: 'secretPAT',
};
const token = await getAuthenticationToken(authentication);
expect(token).toBe('Bearer secretPAT');
});