isUserInAppTenant tests working
This commit is contained in:
parent
6404f07cfe
commit
e6ac534fca
|
@ -4,11 +4,14 @@ jest.mock("../../context", () => ({
|
|||
isMultiTenant: jest.fn(() => true),
|
||||
}))
|
||||
|
||||
import { addTenantToUrl } from "../"
|
||||
import { isMultiTenant } from "../../context"
|
||||
import { addTenantToUrl, isUserInAppTenant, getTenantIDFromCtx } from "../"
|
||||
import { isMultiTenant, getTenantIDFromAppID } from "../../context"
|
||||
const mockedIsMultiTenant = isMultiTenant as jest.MockedFunction<
|
||||
typeof isMultiTenant
|
||||
>
|
||||
const mockedGetTenantIDFromAppID = getTenantIDFromAppID as jest.MockedFunction<
|
||||
typeof getTenantIDFromAppID
|
||||
>
|
||||
describe("addTenantToUrl", () => {
|
||||
it("should append tenantId parameter to the URL", () => {
|
||||
const url = "https://budibase.com"
|
||||
|
@ -32,3 +35,38 @@ describe("addTenantToUrl", () => {
|
|||
expect(addTenantToUrl(url)).toEqual(expectedUrl)
|
||||
})
|
||||
})
|
||||
|
||||
jest.mock("../../context", () => ({
|
||||
getTenantId: jest.fn(() => "budibase"),
|
||||
getTenantIDFromAppID: jest.fn(() => "budibase"),
|
||||
}))
|
||||
describe("isUserInAppTenant", () => {
|
||||
const mockUser = { tenantId: "budibase" }
|
||||
|
||||
it("returns true if user tenant ID matches app tenant ID", () => {
|
||||
const appId = "app-budibase"
|
||||
const result = isUserInAppTenant(appId, mockUser)
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("uses default tenant ID if user is not provided", () => {
|
||||
const appId = "app-budibase"
|
||||
const result = isUserInAppTenant(appId)
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("uses default tenant ID if app tenant ID is not found", () => {
|
||||
const appId = "not-budibase-app"
|
||||
const result = isUserInAppTenant(appId, mockUser)
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false if user tenant ID does not match app tenant ID", () => {
|
||||
const appId = "app-budibase"
|
||||
mockedGetTenantIDFromAppID.mockImplementation(() => "not-budibase")
|
||||
const result = isUserInAppTenant(appId, mockUser)
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("getTenantIDFromCtx", () => {})
|
||||
|
|
Loading…
Reference in New Issue