From 957706fc9119b138f8d1edf7517097f1084f2586 Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Tue, 3 Nov 2020 14:30:20 +0000 Subject: [PATCH] Linting and fixing client test case, have to mock getAppId as the location will never be set during testing. --- packages/client/src/api/index.js | 6 +++--- packages/client/tests/screenRouting.spec.js | 3 +++ packages/client/tests/testAppDef.js | 6 ++++-- packages/server/src/api/controllers/auth.js | 2 +- packages/standard-components/src/Navigation.svelte | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/client/src/api/index.js b/packages/client/src/api/index.js index 39139197a3..1279ebcb89 100644 --- a/packages/client/src/api/index.js +++ b/packages/client/src/api/index.js @@ -1,5 +1,5 @@ -import {authenticate} from "./authenticate" -import {getAppIdFromPath} from "../render/getAppId"; +import { authenticate } from "./authenticate" +import { getAppIdFromPath } from "../render/getAppId" const apiCall = method => async ({ url, body }) => { const response = await fetch(url, { @@ -38,7 +38,7 @@ const del = apiCall("DELETE") const ERROR_MEMBER = "##error" const error = message => { // appStore.update(s => s["##error_message"], message) - return {[ERROR_MEMBER]: message} + return { [ERROR_MEMBER]: message } } const isSuccess = obj => !obj || !obj[ERROR_MEMBER] diff --git a/packages/client/tests/screenRouting.spec.js b/packages/client/tests/screenRouting.spec.js index 3e4818961d..10f251f032 100644 --- a/packages/client/tests/screenRouting.spec.js +++ b/packages/client/tests/screenRouting.spec.js @@ -1,5 +1,8 @@ import { load, makePage, makeScreen, walkComponentTree } from "./testAppDef" import { isScreenSlot } from "../src/render/builtinComponents" +jest.mock("../src/render/getAppId", () => ({ + getAppIdFromPath: () => "TEST_APP_ID" +})) describe("screenRouting", () => { it("should load correct screen, for initial URL", async () => { diff --git a/packages/client/tests/testAppDef.js b/packages/client/tests/testAppDef.js index 803a7f770b..c9a5bb1cc0 100644 --- a/packages/client/tests/testAppDef.js +++ b/packages/client/tests/testAppDef.js @@ -1,15 +1,17 @@ import jsdom, { JSDOM } from "jsdom" import { loadBudibase } from "../src/index" +export const APP_ID = "TEST_APP_ID" + export const load = async (page, screens, url, host = "test.com") => { screens = screens || [] url = url || "/" const fullUrl = `http://${host}${url}` const cookieJar = new jsdom.CookieJar() - const cookie = `${btoa("{}")}.${btoa('{"appId":"TEST_APP_ID"}')}.signature` + const cookie = `${btoa("{}")}.${btoa(`{"appId":"${APP_ID}"}`)}.signature` cookieJar.setCookie( - `budibase:TEST_APP_ID:local=${cookie};domain=${host};path=/`, + `budibase:${APP_ID}:local=${cookie};domain=${host};path=/`, fullUrl, { looseMode: false, diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index 017a938a6a..2c162587b3 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -33,7 +33,7 @@ exports.authenticate = async ctx => { const payload = { userId: dbUser._id, accessLevelId: dbUser.accessLevelId, - version: app.version + version: app.version, } // if in cloud add the user api key if (env.CLOUD) { diff --git a/packages/standard-components/src/Navigation.svelte b/packages/standard-components/src/Navigation.svelte index 0ee5fc7f23..dda860414d 100644 --- a/packages/standard-components/src/Navigation.svelte +++ b/packages/standard-components/src/Navigation.svelte @@ -25,7 +25,7 @@ document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;` } } - location.href=`/${appId}` + location.href = `/${appId}` }