1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/src/lib/openapi/index.test.ts
Christopher Kolstad 6673d131fe
feat: biome lint (#4853)
This commit changes our linter/formatter to biome (https://biomejs.dev/)
Causing our prehook to run almost instantly, and our "yarn lint" task to
run in sub 100ms.

Some trade-offs:
* Biome isn't quite as well established as ESLint
* Are we ready to install a different vscode plugin (the biome plugin)
instead of the prettier plugin


The configuration set for biome also has a set of recommended rules,
this is turned on by default, in order to get to something that was
mergeable I have turned off a couple the rules we seemed to violate the
most, that we also explicitly told eslint to ignore.
2023-09-29 14:18:21 +02:00

73 lines
2.2 KiB
TypeScript

import { createOpenApiSchema, removeJsonSchemaProps, schemas } from './index';
import fs from 'fs';
import path from 'path';
test('all schema files should be added to the schemas object', () => {
const schemaFileNames = fs
.readdirSync(path.join(__dirname, 'spec'))
.filter((fileName) => fileName.endsWith('-schema.ts'));
const expectedSchemaNames = schemaFileNames.map((fileName) => {
return fileName
.replace(/\.ts$/, '')
.replace(/-./g, (x) => x[1].toUpperCase());
});
const addedSchemaNames = Object.keys(schemas);
expect(expectedSchemaNames.sort()).toEqual(addedSchemaNames.sort());
});
test('removeJsonSchemaProps', () => {
expect(
removeJsonSchemaProps({ a: 'b', $id: 'c', components: {} }),
).toMatchInlineSnapshot(`
{
"a": "b",
}
`);
});
describe('createOpenApiSchema', () => {
test('if no baseurl do not return servers', () => {
expect(
createOpenApiSchema({
unleashUrl: 'https://example.com',
baseUriPath: '',
}).servers,
).toEqual([]);
});
test('if baseurl is set leave it in serverUrl', () => {
expect(
createOpenApiSchema({
unleashUrl: 'https://example.com/demo2',
baseUriPath: '/demo2',
}).servers?.[0].url,
).toEqual('https://example.com/demo2');
});
test('if baseurl does not start with /, cowardly refuses to strip', () => {
expect(
createOpenApiSchema({
unleashUrl: 'https://example.com/demo2',
baseUriPath: 'example',
}).servers?.[0].url,
).toEqual('https://example.com/demo2');
});
test('avoids double trailing slash', () => {
expect(
createOpenApiSchema({
unleashUrl: 'https://example.com/example/',
baseUriPath: 'example',
}).servers?.[0].url,
).toEqual('https://example.com');
expect(
createOpenApiSchema({
unleashUrl: 'https://example.com/example/',
baseUriPath: '/example',
}).servers?.[0].url,
).toEqual('https://example.com/example');
});
});