Fixing test mocking.
This commit is contained in:
parent
5d9b3af332
commit
6817d6cf46
|
@ -32,35 +32,31 @@ function mockAuthWithNoCookie() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
jest.mock("@budibase/backend-core/utils", () => ({
|
||||||
utils: {
|
|
||||||
getAppId: jest.fn(),
|
getAppId: jest.fn(),
|
||||||
setCookie: jest.fn(),
|
setCookie: jest.fn(),
|
||||||
getCookie: jest.fn(),
|
getCookie: jest.fn(),
|
||||||
},
|
}))
|
||||||
constants: {
|
jest.mock("@budibase/backend-core/constants", () => ({
|
||||||
Cookies: {},
|
Cookies: {},
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockAuthWithCookie() {
|
function mockAuthWithCookie() {
|
||||||
jest.resetModules()
|
jest.resetModules()
|
||||||
mockWorker()
|
mockWorker()
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
jest.mock("@budibase/backend-core/utils", () => ({
|
||||||
utils: {
|
|
||||||
getAppId: () => {
|
getAppId: () => {
|
||||||
return "app_test"
|
return "app_test"
|
||||||
},
|
},
|
||||||
setCookie: jest.fn(),
|
setCookie: jest.fn(),
|
||||||
getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
|
getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
|
||||||
},
|
}))
|
||||||
constants: {
|
jest.mock("@budibase/backend-core/constants", () => ({
|
||||||
Cookies: {
|
Cookies: {
|
||||||
Auth: "auth",
|
Auth: "auth",
|
||||||
CurrentApp: "currentapp",
|
CurrentApp: "currentapp",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,32 +136,30 @@ describe("Current app middleware", () => {
|
||||||
|
|
||||||
it("should perform correct when no cookie exists", async () => {
|
it("should perform correct when no cookie exists", async () => {
|
||||||
mockReset()
|
mockReset()
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
jest.mock("@budibase/backend-core/utils", () => ({
|
||||||
utils: {
|
|
||||||
getAppId: () => {
|
getAppId: () => {
|
||||||
return "app_test"
|
return "app_test"
|
||||||
},
|
},
|
||||||
setCookie: jest.fn(),
|
setCookie: jest.fn(),
|
||||||
getCookie: jest.fn(),
|
getCookie: jest.fn(),
|
||||||
},
|
}))
|
||||||
constants: {
|
jest.mock("@budibase/backend-core/constants", () => ({
|
||||||
Cookies: {},
|
Cookies: {},
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
await checkExpected(true)
|
await checkExpected(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("lastly check what occurs when cookie doesn't need updated", async () => {
|
it("lastly check what occurs when cookie doesn't need updated", async () => {
|
||||||
mockReset()
|
mockReset()
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
jest.mock("@budibase/backend-core/utils", () => ({
|
||||||
utils: {
|
|
||||||
getAppId: () => {
|
getAppId: () => {
|
||||||
return "app_test"
|
return "app_test"
|
||||||
},
|
},
|
||||||
setCookie: jest.fn(),
|
setCookie: jest.fn(),
|
||||||
getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}),
|
getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}),
|
||||||
},
|
}))
|
||||||
constants: { Cookies: {} },
|
jest.mock("@budibase/backend-core/constants", () => ({
|
||||||
|
Cookies: {},
|
||||||
}))
|
}))
|
||||||
await checkExpected(false)
|
await checkExpected(false)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue