mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const generate = require('./scripts/generate');
|
|
const copy = require('./scripts/copy');
|
|
const compileWithBabel = require('./scripts/compileWithBabel');
|
|
const server = require('./scripts/server');
|
|
const browser = require('./scripts/browser');
|
|
|
|
describe('v3.fetch', () => {
|
|
|
|
beforeAll(async () => {
|
|
await generate('v3/babel', 'v3', 'fetch', true, true);
|
|
await copy('v3/babel');
|
|
compileWithBabel('v3/babel');
|
|
await server.start('v3/babel');
|
|
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.api;
|
|
OpenAPI.TOKEN = window.tokenRequest;
|
|
OpenAPI.USERNAME = undefined;
|
|
OpenAPI.PASSWORD = undefined;
|
|
return await SimpleService.getCallWithoutParametersAndResponse();
|
|
});
|
|
expect(result.headers.authorization).toBe('Bearer MY_TOKEN');
|
|
});
|
|
|
|
it('uses credentials', async () => {
|
|
const result = await browser.evaluate(async () => {
|
|
const { OpenAPI, SimpleService } = window.api;
|
|
OpenAPI.TOKEN = undefined;
|
|
OpenAPI.USERNAME = 'username';
|
|
OpenAPI.PASSWORD = 'password';
|
|
return await SimpleService.getCallWithoutParametersAndResponse();
|
|
});
|
|
expect(result.headers.authorization).toBe('Basic dXNlcm5hbWU6cGFzc3dvcmQ=');
|
|
});
|
|
|
|
it('complexService', async () => {
|
|
const result = await browser.evaluate(async () => {
|
|
const { ComplexService } = window.api;
|
|
return await ComplexService.complexTypes({
|
|
first: {
|
|
second: {
|
|
third: 'Hello World!'
|
|
}
|
|
}
|
|
});
|
|
});
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|