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()
jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true
core.cache.user.getUser = () => ({ _id: "us_uuid1" })
core.utils.getAppIdFromCtx = jest.fn()
core.utils.setCookie = jest.fn()
core.utils.getCookie = jest.fn()
return core
return {
...core,
db: {
...core.db,
dbExists: () => true,
},
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()
jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true
core.cache.user.getUser = () => ({ _id: "us_uuid1" })
core.utils.getAppIdFromCtx = () => "app_test"
core.utils.getCookie = () => ({ appId: "app_different", roleId: "PUBLIC" })
core.utils.setCookie = jest.fn()
core.utils.clearCookie = jest.fn()
return core
return {
...core,
db: {
...core.db,
dbExists: () => true,
},
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()
jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core")
core.db.dbExists = () => true
core.cache.user.getUser = () => ({ _id: "us_uuid1" })
core.utils.getAppIdFromCtx = () => "app_test"
core.utils.getCookie = () => ({
appId: "app_different",
roleId: "PUBLIC",
})
core.utils.setCookie = jest.fn()
core.utils.clearCookie = jest.fn()
return core
return {
...core,
db: {
...core.db,
dbExists: () => true,
},
utils: {
getAppIdFromCtx: () => {
return "app_test"
},
setCookie: jest.fn(),
getCookie: jest.fn(),
},
cache: {
user: {
getUser: async id => {
return {
_id: "us_uuid1",
}
},
},
},
}
})
await checkExpected()
})