|
1 |
| -import * as sinon from 'sinon'; |
2 |
| -import { test } from 'vitest'; |
| 1 | +import { describe, test } from 'vitest'; |
3 | 2 | import { BaseClient } from '@jirajs';
|
4 | 3 |
|
5 |
| -const XAtlassianToken = 'X-Atlassian-Token'; |
| 4 | +describe('BaseClient', () => { |
| 5 | + test('shouldn\'t display error message for correct host urls', () => { |
| 6 | + new BaseClient({ |
| 7 | + host: 'http://localhost', |
| 8 | + }); |
6 | 9 |
|
7 |
| -test('should create X-Atlassian-Token: no-check header in requests', async ({ expect }) => { |
8 |
| - const client = new BaseClient({ |
9 |
| - host: 'http://localhost', |
10 |
| - noCheckAtlassianToken: true, |
| 10 | + new BaseClient({ host: 'https://localhost/' }); |
11 | 11 | });
|
12 | 12 |
|
13 |
| - // @ts-expect-error Wrong typings |
14 |
| - const defaultHeaders: Record<string, string> = client.instance.defaults.headers; |
| 13 | + test('should display error message for incorrect host url', ({ expect }) => { |
| 14 | + const errorMessage = 'Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?'; |
15 | 15 |
|
16 |
| - expect(defaultHeaders[XAtlassianToken]).toBe('no-check'); |
17 |
| - |
18 |
| - const sendRequestStub = sinon.stub(client, 'sendRequest'); |
19 |
| - |
20 |
| - // @ts-expect-error Wrong typings |
21 |
| - await client.sendRequest({}, undefined); // TODO problem with never type |
22 |
| - |
23 |
| - expect(sendRequestStub.calledOnce).toBeTruthy(); |
24 |
| - |
25 |
| - const callArgument = sendRequestStub.getCall(0).args[0]; |
26 |
| - |
27 |
| - expect(callArgument.headers?.[XAtlassianToken]).toBe(undefined); |
28 |
| -}); |
29 |
| - |
30 |
| -test('should not create X-Atlassian-Token: no-check header in requests case 1', async ({ expect }) => { |
31 |
| - const client = new BaseClient({ |
32 |
| - host: 'http://localhost', |
33 |
| - noCheckAtlassianToken: false, |
34 |
| - }); |
35 |
| - // @ts-expect-error Wrong typings |
36 |
| - const defaultHeaders: Record<string, string> = client.instance.defaults.headers; |
37 |
| - |
38 |
| - expect(defaultHeaders[XAtlassianToken]).toBe(undefined); |
39 |
| - |
40 |
| - const sendRequestStub = sinon.stub(client, 'sendRequest'); |
41 |
| - |
42 |
| - // @ts-expect-error Wrong typings |
43 |
| - await client.sendRequest({}, undefined); // TODO problem with never type |
44 |
| - expect(sendRequestStub.calledOnce).toBeTruthy(); |
45 |
| - |
46 |
| - const callArgument = sendRequestStub.getCall(0).args[0]; |
47 |
| - |
48 |
| - expect(callArgument.headers?.[XAtlassianToken]).toBe(undefined); |
49 |
| -}); |
50 |
| - |
51 |
| -test('should create X-Atlassian-Token: no-check header in requests case 2', async ({ expect }) => { |
52 |
| - const client = new BaseClient({ |
53 |
| - host: 'http://localhost', |
| 16 | + expect(() => new BaseClient({ host: '' })).toThrowError(errorMessage); |
| 17 | + expect(() => new BaseClient({ host: 'localhost' })).toThrowError(errorMessage); |
| 18 | + expect(() => new BaseClient({ host: 'example.com' })).toThrowError(errorMessage); |
54 | 19 | });
|
55 |
| - |
56 |
| - // @ts-expect-error Wrong typings |
57 |
| - const defaultHeaders: Record<string, string> = client.instance.defaults.headers; |
58 |
| - |
59 |
| - expect(defaultHeaders[XAtlassianToken]).toBe(undefined); |
60 |
| - |
61 |
| - const sendRequestStub = sinon.stub(client, 'sendRequest'); |
62 |
| - |
63 |
| - // @ts-expect-error Wrong typings |
64 |
| - await client.sendRequest({}, undefined); // TODO problem with never type |
65 |
| - |
66 |
| - expect(sendRequestStub.calledOnce).toBeTruthy(); |
67 |
| - |
68 |
| - const callArgument = sendRequestStub.getCall(0).args[0]; |
69 |
| - |
70 |
| - expect(callArgument.headers?.[XAtlassianToken]).toBe(undefined); |
71 |
| -}); |
72 |
| - |
73 |
| -test('shouldn\'t display error message for correct host urls', () => { |
74 |
| - new BaseClient({ |
75 |
| - host: 'http://localhost', |
76 |
| - }); |
77 |
| - |
78 |
| - new BaseClient({ host: 'https://localhost/' }); |
79 |
| -}); |
80 |
| - |
81 |
| -test('should display error message for incorrect host url', ({ expect }) => { |
82 |
| - const errorMessage = 'Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?'; |
83 |
| - |
84 |
| - expect(() => new BaseClient({ host: '' })).toThrowError(errorMessage); |
85 |
| - expect(() => new BaseClient({ host: 'localhost' })).toThrowError(errorMessage); |
86 |
| - expect(() => new BaseClient({ host: 'example.com' })).toThrowError(errorMessage); |
87 | 20 | });
|
0 commit comments