Linting and fixing client test case, have to mock getAppId as the location will never be set during testing.
This commit is contained in:
parent
27871c1bc0
commit
957706fc91
|
@ -1,5 +1,5 @@
|
||||||
import {authenticate} from "./authenticate"
|
import { authenticate } from "./authenticate"
|
||||||
import {getAppIdFromPath} from "../render/getAppId";
|
import { getAppIdFromPath } from "../render/getAppId"
|
||||||
|
|
||||||
const apiCall = method => async ({ url, body }) => {
|
const apiCall = method => async ({ url, body }) => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
@ -38,7 +38,7 @@ const del = apiCall("DELETE")
|
||||||
const ERROR_MEMBER = "##error"
|
const ERROR_MEMBER = "##error"
|
||||||
const error = message => {
|
const error = message => {
|
||||||
// appStore.update(s => s["##error_message"], message)
|
// appStore.update(s => s["##error_message"], message)
|
||||||
return {[ERROR_MEMBER]: message}
|
return { [ERROR_MEMBER]: message }
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSuccess = obj => !obj || !obj[ERROR_MEMBER]
|
const isSuccess = obj => !obj || !obj[ERROR_MEMBER]
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import { load, makePage, makeScreen, walkComponentTree } from "./testAppDef"
|
import { load, makePage, makeScreen, walkComponentTree } from "./testAppDef"
|
||||||
import { isScreenSlot } from "../src/render/builtinComponents"
|
import { isScreenSlot } from "../src/render/builtinComponents"
|
||||||
|
jest.mock("../src/render/getAppId", () => ({
|
||||||
|
getAppIdFromPath: () => "TEST_APP_ID"
|
||||||
|
}))
|
||||||
|
|
||||||
describe("screenRouting", () => {
|
describe("screenRouting", () => {
|
||||||
it("should load correct screen, for initial URL", async () => {
|
it("should load correct screen, for initial URL", async () => {
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import jsdom, { JSDOM } from "jsdom"
|
import jsdom, { JSDOM } from "jsdom"
|
||||||
import { loadBudibase } from "../src/index"
|
import { loadBudibase } from "../src/index"
|
||||||
|
|
||||||
|
export const APP_ID = "TEST_APP_ID"
|
||||||
|
|
||||||
export const load = async (page, screens, url, host = "test.com") => {
|
export const load = async (page, screens, url, host = "test.com") => {
|
||||||
screens = screens || []
|
screens = screens || []
|
||||||
url = url || "/"
|
url = url || "/"
|
||||||
|
|
||||||
const fullUrl = `http://${host}${url}`
|
const fullUrl = `http://${host}${url}`
|
||||||
const cookieJar = new jsdom.CookieJar()
|
const cookieJar = new jsdom.CookieJar()
|
||||||
const cookie = `${btoa("{}")}.${btoa('{"appId":"TEST_APP_ID"}')}.signature`
|
const cookie = `${btoa("{}")}.${btoa(`{"appId":"${APP_ID}"}`)}.signature`
|
||||||
cookieJar.setCookie(
|
cookieJar.setCookie(
|
||||||
`budibase:TEST_APP_ID:local=${cookie};domain=${host};path=/`,
|
`budibase:${APP_ID}:local=${cookie};domain=${host};path=/`,
|
||||||
fullUrl,
|
fullUrl,
|
||||||
{
|
{
|
||||||
looseMode: false,
|
looseMode: false,
|
||||||
|
|
|
@ -33,7 +33,7 @@ exports.authenticate = async ctx => {
|
||||||
const payload = {
|
const payload = {
|
||||||
userId: dbUser._id,
|
userId: dbUser._id,
|
||||||
accessLevelId: dbUser.accessLevelId,
|
accessLevelId: dbUser.accessLevelId,
|
||||||
version: app.version
|
version: app.version,
|
||||||
}
|
}
|
||||||
// if in cloud add the user api key
|
// if in cloud add the user api key
|
||||||
if (env.CLOUD) {
|
if (env.CLOUD) {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
|
document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
location.href=`/${appId}`
|
location.href = `/${appId}`
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue