openapi-typescript-codegen/src/utils/writeClientIndex.spec.ts
Cajetan Grill d97edce979 Updated file system tests to be OS-agnostic
- Test results for write operations are now designed to match irrespective of the system's path encoding: The previously used UNIX-style path strings do not match on Windows systems. Therefore, expected paths are now being resolved as they are in their corresponding write function.
- Unit tests should now pass on all systems.
2023-07-28 11:22:56 +02:00

44 lines
1.4 KiB
TypeScript

import { resolve } from 'path';
import type { Client } from '../client/interfaces/Client';
import { writeFile } from './fileSystem';
import type { Templates } from './registerHandlebarTemplates';
import { writeClientIndex } from './writeClientIndex';
jest.mock('./fileSystem');
describe('writeClientIndex', () => {
it('should write to filesystem', async () => {
const client: Client = {
server: 'http://localhost:8080',
version: '1.0',
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 writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
expect(writeFile).toBeCalledWith(resolve('/', '/index.ts'), 'index');
});
});