Refactor UserAuthorization and Realtime; update mock implementation and add validation for tenantId

This commit is contained in:
Simon Larsen 2024-09-27 14:21:47 +01:00
parent a0d77ac104
commit d48b725f6a
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
2 changed files with 9 additions and 1 deletions

View File

@ -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);

View File

@ -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,