-
Notifications
You must be signed in to change notification settings - Fork 35
/
api-key.spec.ts
33 lines (22 loc) · 957 Bytes
/
api-key.spec.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
import { RequestOptions } from '../core/request-plugin';
import { ApiKeyRequest } from './api-key.request';
describe('Api Key Request Plugin', () => {
let options: RequestOptions;
beforeEach(() => {
const headers = new Headers();
jest.spyOn(headers, 'append');
options = { headers, basePath: 'http://test.com/truc', method: 'get' };
});
it('should add the API Key to the headers', async () => {
const plugin = new ApiKeyRequest('test', 'testKey');
const runner = plugin.load();
await runner.transform(options);
expect(options.headers.append).toHaveBeenCalledWith('testKey', 'test');
});
it('should execute the function to add the API Key to the headers', async () => {
const plugin = new ApiKeyRequest(() => Promise.resolve('test'), 'testKey');
const runner = plugin.load();
await runner.transform(options);
expect(options.headers.append).toHaveBeenCalledWith('testKey', 'test');
});
});