Add a test for the support of external schemas in the router
Signed-off-by: David Festal <dfestal@redhat.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"backstageConfigSchemaVersion": 1,
|
||||
"schemas": []
|
||||
}
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import request from 'supertest';
|
||||
import { createRouter } from './router';
|
||||
import { loadConfigSchema } from '@backstage/config-loader';
|
||||
|
||||
jest.mock('../lib/config', () => ({
|
||||
injectConfig: jest.fn(),
|
||||
@@ -115,3 +116,75 @@ describe('createRouter with static fallback handler', () => {
|
||||
expect(response3.status).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createRouter config schema test', () => {
|
||||
const libConfigs = require('../lib/config');
|
||||
const libConfigsActual = jest.requireActual('../lib/config');
|
||||
const readConfigsMock: jest.Mock = libConfigs.readConfigs;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
readConfigsMock.mockImplementation(libConfigsActual.readConfigs);
|
||||
});
|
||||
|
||||
it('uses an external schema', async () => {
|
||||
await createRouter({
|
||||
logger: getVoidLogger(),
|
||||
config: new ConfigReader({
|
||||
test: 'value',
|
||||
}),
|
||||
appPackageName: 'example-app',
|
||||
schema: await loadConfigSchema({
|
||||
serialized: {
|
||||
schemas: [
|
||||
{
|
||||
value: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
test: {
|
||||
visibility: 'frontend',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
path: '/mock',
|
||||
},
|
||||
],
|
||||
backstageConfigSchemaVersion: 1,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const results = readConfigsMock.mock.results;
|
||||
expect(results.length).toBe(1);
|
||||
|
||||
const mockedResult = results[0];
|
||||
expect(mockedResult.type).toBe('return');
|
||||
const result = await (mockedResult.value as Promise<AppConfig[]>);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].data).toStrictEqual({
|
||||
test: 'value',
|
||||
});
|
||||
});
|
||||
|
||||
it('uses no external schema', async () => {
|
||||
await createRouter({
|
||||
logger: getVoidLogger(),
|
||||
config: new ConfigReader({
|
||||
test: 'value',
|
||||
}),
|
||||
appPackageName: 'example-app',
|
||||
});
|
||||
|
||||
const results = readConfigsMock.mock.results;
|
||||
expect(results.length).toBe(1);
|
||||
|
||||
const mockedResult = results[0];
|
||||
expect(mockedResult.type).toBe('return');
|
||||
const result = await (mockedResult.value as Promise<AppConfig[]>);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].data).toStrictEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user