mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
Refactor UserAuthorization and Realtime; update mock implementation and add validation for tenantId
This commit is contained in:
parent
a0d77ac104
commit
d48b725f6a
@ -34,6 +34,7 @@ import {
|
||||
} from "@jest/globals";
|
||||
import { getJestSpyOn } from "Common/Tests/Spy";
|
||||
import getJestMockFunction from "Common/Tests/MockType";
|
||||
import UserPermissionUtil from "../../../Server/Utils/UserPermission/UserPermission";
|
||||
|
||||
jest.mock("../../../Server/Utils/Logger");
|
||||
jest.mock("../../../Server/Middleware/ProjectAuthorization");
|
||||
@ -718,7 +719,7 @@ describe("UserMiddleware", () => {
|
||||
|
||||
const spyGetDefaultUserTenantAccessPermission: jest.SpyInstance =
|
||||
getJestSpyOn(
|
||||
AccessTokenService,
|
||||
UserPermissionUtil,
|
||||
"getDefaultUserTenantAccessPermission",
|
||||
).mockReturnValueOnce(mockedUserTenantAccessPermission);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import SocketIO, { Socket } from "socket.io-client";
|
||||
import ModelEventType from "../../Types/Realtime/ModelEventType";
|
||||
import ListenToModelEventJSON from "../../Types/Realtime/ListenToModelEventJSON";
|
||||
import EventName from "../../Types/Realtime/EventName";
|
||||
import BadDataException from "../../Types/Exception/BadDataException";
|
||||
|
||||
export interface ListenToModelEvent<
|
||||
Model extends AnalyticsBaseModel | BaseModel,
|
||||
@ -42,6 +43,12 @@ export default abstract class Realtime {
|
||||
this.init();
|
||||
}
|
||||
|
||||
if (!listenToModelEvent.tenantId) {
|
||||
throw new BadDataException(
|
||||
"TenantId is required to listen to model event.",
|
||||
);
|
||||
}
|
||||
|
||||
const listenToModelEventJSON: ListenToModelEventJSON = {
|
||||
eventType: listenToModelEvent.eventType,
|
||||
modelType: DatabaseType.Database,
|
||||
|
Loading…
Reference in New Issue
Block a user