forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2.xhr.spec.ts
47 lines (43 loc) · 1.66 KB
/
v2.xhr.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import browser from './scripts/browser';
import { cleanup } from './scripts/cleanup';
import { compileWithTypescript } from './scripts/compileWithTypescript';
import { copyAsset } from './scripts/copyAsset';
import { generateClient } from './scripts/generateClient';
import server from './scripts/server';
describe('v2.xhr', () => {
beforeAll(async () => {
cleanup('v2/xhr');
await generateClient('v2/xhr', 'v2', 'xhr');
copyAsset('index.html', 'v2/xhr/index.html');
copyAsset('main.ts', 'v2/xhr/main.ts');
compileWithTypescript('v2/xhr');
await server.start('v2/xhr');
await browser.start();
}, 30000);
afterAll(async () => {
await browser.stop();
await server.stop();
});
it('requests token', async () => {
await browser.exposeFunction('tokenRequest', jest.fn().mockResolvedValue('MY_TOKEN'));
const result = await browser.evaluate(async () => {
const { OpenAPI, SimpleService } = (window as any).api;
OpenAPI.TOKEN = (window as any).tokenRequest;
return await SimpleService.getCallWithoutParametersAndResponse();
});
expect(result.headers.authorization).toBe('Bearer MY_TOKEN');
});
it('supports complex params', async () => {
const result = await browser.evaluate(async () => {
const { ComplexService } = (window as any).api;
return await ComplexService.complexTypes({
first: {
second: {
third: 'Hello World!',
},
},
});
});
expect(result).toBeDefined();
});
});