UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

56 lines 2.27 kB
import { createOpenApiSchema, removeJsonSchemaProps, schemas, } from './index.js'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); 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'); }); }); //# sourceMappingURL=index.test.js.map