openapi-typescript-codegen/src/utils/writeClient.spec.ts
2022-01-25 13:34:23 +01:00

60 lines
1.7 KiB
TypeScript

import type { Client } from '../client/interfaces/Client';
import { HttpClient } from '../HttpClient';
import { Indent } from '../Indent';
import { mkdir, rmdir, writeFile } from './fileSystem';
import type { Templates } from './registerHandlebarTemplates';
import { writeClient } from './writeClient';
jest.mock('./fileSystem');
describe('writeClient', () => {
it('should write to filesystem', async () => {
const client: Client = {
server: 'http://localhost:8080',
version: 'v1',
models: [],
services: [],
};
const templates: Templates = {
index: () => 'index',
client: () => 'client',
exports: {
model: () => 'model',
schema: () => 'schema',
service: () => 'service',
},
core: {
settings: () => 'settings',
apiError: () => 'apiError',
apiRequestOptions: () => 'apiRequestOptions',
apiResult: () => 'apiResult',
cancelablePromise: () => 'cancelablePromise',
request: () => 'request',
baseHttpRequest: () => 'baseHttpRequest',
httpRequest: () => 'httpRequest',
},
};
await writeClient(
client,
templates,
'./dist',
HttpClient.FETCH,
false,
false,
true,
true,
true,
true,
Indent.SPACE_4,
'Service',
'AppClient'
);
expect(rmdir).toBeCalled();
expect(mkdir).toBeCalled();
expect(writeFile).toBeCalled();
});
});