unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
66 lines • 2.79 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
test('all schema files should be added to the schemas object', () => {
const schemaFileNames = fs_1.default
.readdirSync(path_1.default.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(index_1.schemas);
expect(expectedSchemaNames.sort()).toEqual(addedSchemaNames.sort());
});
test('all schema $id attributes should have the expected format', () => {
const schemaIds = Object.values(index_1.schemas).map((schema) => schema.$id);
const schemaIdRegExp = new RegExp(`^#/components/schemas/[a-z][a-zA-Z]+$`);
schemaIds.forEach((schemaId) => {
expect(schemaId).toMatch(schemaIdRegExp);
});
});
test('removeJsonSchemaProps', () => {
expect((0, index_1.removeJsonSchemaProps)({ a: 'b', $id: 'c', components: {} }))
.toMatchInlineSnapshot(`
{
"a": "b",
}
`);
});
describe('createOpenApiSchema', () => {
test('createOpenApiSchema url', () => {
expect((0, index_1.createOpenApiSchema)({
unleashUrl: 'https://example.com',
baseUriPath: '',
}).servers[0].url).toEqual('https://example.com');
});
test('if baseurl is set strips from serverUrl', () => {
expect((0, index_1.createOpenApiSchema)({
unleashUrl: 'https://example.com/demo2',
baseUriPath: '/demo2',
}).servers[0].url).toEqual('https://example.com');
});
test('if baseurl does not end with suffix, cowardly refuses to strip', () => {
expect((0, index_1.createOpenApiSchema)({
unleashUrl: 'https://example.com/demo2',
baseUriPath: 'example',
}).servers[0].url).toEqual('https://example.com/demo2');
});
test('avoids double trailing slash', () => {
expect((0, index_1.createOpenApiSchema)({
unleashUrl: 'https://example.com/example/',
baseUriPath: 'example',
}).servers[0].url).toEqual('https://example.com');
expect((0, index_1.createOpenApiSchema)({
unleashUrl: 'https://example.com/example/',
baseUriPath: '/example',
}).servers[0].url).toEqual('https://example.com');
});
});
//# sourceMappingURL=index.test.js.map