test(api): Add getRootConfig test.

This commit is contained in:
Sam Tolmay 2022-02-03 08:02:51 +02:00
parent 02abd41e8e
commit 9fadb6e37e
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0

View File

@ -0,0 +1,83 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import testContext from '../../test/testContext.js';
const mockGetMenu = jest.fn();
jest.mock('./menus/getMenus.js', () => ({
__esModule: true,
default: mockGetMenu,
}));
const mockReadConfigFile = jest.fn();
const context = testContext({ readConfigFile: mockReadConfigFile });
beforeEach(() => {
mockReadConfigFile.mockReset();
});
test('getRootConfig', async () => {
const getRootConfig = (await import('./getRootConfig.js')).default;
mockReadConfigFile.mockImplementation((path) => {
if (path === 'global.json') {
return {
global: true,
};
}
return null;
});
const menus = [
{
menuId: 'default',
links: [
{
id: 'menuitem:default:0',
menuItemId: '0',
type: 'MenuLink',
pageId: 'page',
auth: { public: true },
},
],
},
];
mockGetMenu.mockImplementation(() => menus);
const res = await getRootConfig(context);
expect(res).toEqual({
authenticated: undefined,
home: {
configured: false,
pageId: 'page',
},
lowdefyGlobal: {
global: true,
},
menus: [
{
menuId: 'default',
links: [
{
id: 'menuitem:default:0',
menuItemId: '0',
type: 'MenuLink',
pageId: 'page',
auth: { public: true },
},
],
},
],
});
});