From 9fadb6e37ec81dedae870ff80578fff9a34ccf47 Mon Sep 17 00:00:00 2001 From: Sam Tolmay Date: Thu, 3 Feb 2022 08:02:51 +0200 Subject: [PATCH] test(api): Add getRootConfig test. --- .../routes/rootConfig/getRootConfig.test.js | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 packages/api/src/routes/rootConfig/getRootConfig.test.js diff --git a/packages/api/src/routes/rootConfig/getRootConfig.test.js b/packages/api/src/routes/rootConfig/getRootConfig.test.js new file mode 100644 index 000000000..0428bd169 --- /dev/null +++ b/packages/api/src/routes/rootConfig/getRootConfig.test.js @@ -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 }, + }, + ], + }, + ], + }); +});