Resetting test.

This commit is contained in:
mike12345567 2023-11-17 16:23:41 +00:00
parent 7fb6c0927a
commit 34d6a41042
1 changed files with 68 additions and 23 deletions

View File

@ -37,12 +37,27 @@ function mockAuthWithNoCookie() {
mockWorker() mockWorker()
jest.mock("@budibase/backend-core", () => { jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core") const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true return {
core.cache.user.getUser = () => ({ _id: "us_uuid1" }) ...core,
core.utils.getAppIdFromCtx = jest.fn() db: {
core.utils.setCookie = jest.fn() ...core.db,
core.utils.getCookie = jest.fn() dbExists: () => true,
return core },
cache: {
user: {
getUser: async id => {
return {
_id: "us_uuid1",
}
},
},
},
utils: {
getAppIdFromCtx: jest.fn(),
setCookie: jest.fn(),
getCookie: jest.fn(),
},
}
}) })
} }
@ -51,13 +66,30 @@ function mockAuthWithCookie() {
mockWorker() mockWorker()
jest.mock("@budibase/backend-core", () => { jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core") const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true return {
core.cache.user.getUser = () => ({ _id: "us_uuid1" }) ...core,
core.utils.getAppIdFromCtx = () => "app_test" db: {
core.utils.getCookie = () => ({ appId: "app_different", roleId: "PUBLIC" }) ...core.db,
core.utils.setCookie = jest.fn() dbExists: () => true,
core.utils.clearCookie = jest.fn() },
return core utils: {
getAppIdFromCtx: () => {
return "app_test"
},
setCookie: jest.fn(),
clearCookie: jest.fn(),
getCookie: () => ({ appId: "app_different", roleId: "PUBLIC" }),
},
cache: {
user: {
getUser: async id => {
return {
_id: "us_uuid1",
}
},
},
},
}
}) })
} }
@ -145,16 +177,29 @@ describe("Current app middleware", () => {
mockReset() mockReset()
jest.mock("@budibase/backend-core", () => { jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core") const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true return {
core.cache.user.getUser = () => ({ _id: "us_uuid1" }) ...core,
core.utils.getAppIdFromCtx = () => "app_test" db: {
core.utils.getCookie = () => ({ ...core.db,
appId: "app_different", dbExists: () => true,
roleId: "PUBLIC", },
}) utils: {
core.utils.setCookie = jest.fn() getAppIdFromCtx: () => {
core.utils.clearCookie = jest.fn() return "app_test"
return core },
setCookie: jest.fn(),
getCookie: jest.fn(),
},
cache: {
user: {
getUser: async id => {
return {
_id: "us_uuid1",
}
},
},
},
}
}) })
await checkExpected() await checkExpected()
}) })