Merge pull request #3792 from bluewave-labs/chore/purge-team/groups
purge unused groups route, update tests
This commit is contained in:
7 files changed
-43
No files matched your search
@@ -44,7 +44,6 @@ export interface IMonitorController {
|
|||||||
getMonitorsWithChecksByTeamId: RequestHandler;
|
getMonitorsWithChecksByTeamId: RequestHandler;
|
||||||
exportMonitorsToJSON: RequestHandler;
|
exportMonitorsToJSON: RequestHandler;
|
||||||
getAllGames: RequestHandler;
|
getAllGames: RequestHandler;
|
||||||
getGroupsByTeamId: RequestHandler;
|
|
||||||
updateNotifications: RequestHandler;
|
updateNotifications: RequestHandler;
|
||||||
}
|
}
|
||||||
class MonitorController implements IMonitorController {
|
class MonitorController implements IMonitorController {
|
||||||
@@ -365,16 +364,6 @@ class MonitorController implements IMonitorController {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
getGroupsByTeamId = catchAsync(async (req: Request, res: Response) => {
|
|
||||||
const teamId = requireTeamId(req.user?.teamId);
|
|
||||||
const groups = await this.monitorService.getGroupsByTeamId({ teamId });
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
msg: "Groups retrieved successfully",
|
|
||||||
data: groups,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
updateNotifications = catchAsync(async (req: Request, res: Response) => {
|
updateNotifications = catchAsync(async (req: Request, res: Response) => {
|
||||||
updateNotificationsValidation.parse(req.body);
|
updateNotificationsValidation.parse(req.body);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class MonitorRoutes {
|
|||||||
// Team routes
|
// Team routes
|
||||||
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
||||||
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
|
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
|
||||||
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
|
|
||||||
|
|
||||||
// Uptime routes
|
// Uptime routes
|
||||||
this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById);
|
this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ export interface IMonitorsRepository {
|
|||||||
|
|
||||||
// other
|
// other
|
||||||
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<MonitorsSummary>;
|
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<MonitorsSummary>;
|
||||||
findGroupsByTeamId(teamId: string): Promise<string[]>;
|
|
||||||
removeNotificationFromMonitors(notificationId: string): Promise<void>;
|
removeNotificationFromMonitors(notificationId: string): Promise<void>;
|
||||||
removeTagFromMonitors(tagId: string): Promise<void>;
|
removeTagFromMonitors(tagId: string): Promise<void>;
|
||||||
updateNotifications(teamId: string, monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set"): Promise<number>;
|
updateNotifications(teamId: string, monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set"): Promise<number>;
|
||||||
|
|||||||
@@ -382,14 +382,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
findGroupsByTeamId = async (teamId: string): Promise<string[]> => {
|
|
||||||
const groups = await MonitorModel.distinct("group", {
|
|
||||||
teamId: new mongoose.Types.ObjectId(teamId),
|
|
||||||
group: { $nin: [null, ""] },
|
|
||||||
});
|
|
||||||
return groups.sort();
|
|
||||||
};
|
|
||||||
|
|
||||||
removeNotificationFromMonitors = async (notificationId: string): Promise<void> => {
|
removeNotificationFromMonitors = async (notificationId: string): Promise<void> => {
|
||||||
await MonitorModel.updateMany({ notifications: notificationId }, { $pull: { notifications: notificationId } });
|
await MonitorModel.updateMany({ notifications: notificationId }, { $pull: { notifications: notificationId } });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ export interface IMonitorService {
|
|||||||
order?: "asc" | "desc";
|
order?: "asc" | "desc";
|
||||||
}): Promise<MonitorsWithChecksByTeamIdResult>;
|
}): Promise<MonitorsWithChecksByTeamIdResult>;
|
||||||
getAllGames(): GamesMap;
|
getAllGames(): GamesMap;
|
||||||
getGroupsByTeamId(args: { teamId: string }): Promise<string[]>;
|
|
||||||
|
|
||||||
// update
|
// update
|
||||||
editMonitor(args: { teamId: string; monitorId: string; body: Partial<Monitor> }): Promise<Monitor>;
|
editMonitor(args: { teamId: string; monitorId: string; body: Partial<Monitor> }): Promise<Monitor>;
|
||||||
@@ -422,10 +421,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
return this.games;
|
return this.games;
|
||||||
};
|
};
|
||||||
|
|
||||||
getGroupsByTeamId = async ({ teamId }: { teamId: string }): Promise<string[]> => {
|
|
||||||
return await this.monitorsRepository.findGroupsByTeamId(teamId);
|
|
||||||
};
|
|
||||||
|
|
||||||
editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: Partial<Monitor> }) => {
|
editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: Partial<Monitor> }) => {
|
||||||
const editedMonitor = await this.monitorsRepository.updateById(monitorId, teamId, body);
|
const editedMonitor = await this.monitorsRepository.updateById(monitorId, teamId, body);
|
||||||
await this.scheduler.updateJob(editedMonitor);
|
await this.scheduler.updateJob(editedMonitor);
|
||||||
|
|||||||
@@ -119,10 +119,6 @@ export class InMemoryMonitorsRepository implements IMonitorsRepository {
|
|||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
async findGroupsByTeamId(_teamId: string): Promise<string[]> {
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
async removeNotificationFromMonitors(_notificationId: string): Promise<void> {
|
async removeNotificationFromMonitors(_notificationId: string): Promise<void> {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ const createMonitorsRepositoryMock = () =>
|
|||||||
findByIds: jest.fn(),
|
findByIds: jest.fn(),
|
||||||
findMonitorCountByTeamIdAndType: jest.fn(),
|
findMonitorCountByTeamIdAndType: jest.fn(),
|
||||||
findMonitorsSummaryByTeamId: jest.fn(),
|
findMonitorsSummaryByTeamId: jest.fn(),
|
||||||
findGroupsByTeamId: jest.fn(),
|
|
||||||
updateById: jest.fn(),
|
updateById: jest.fn(),
|
||||||
updateNotifications: jest.fn(),
|
updateNotifications: jest.fn(),
|
||||||
togglePauseById: jest.fn(),
|
togglePauseById: jest.fn(),
|
||||||
@@ -746,18 +745,6 @@ describe("MonitorService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getGroupsByTeamId", () => {
|
|
||||||
it("delegates to repository", async () => {
|
|
||||||
const monitorsRepository = createMonitorsRepositoryMock();
|
|
||||||
(monitorsRepository.findGroupsByTeamId as jest.Mock).mockResolvedValue(["group1", "group2"]);
|
|
||||||
const { service } = createService({ monitorsRepository });
|
|
||||||
|
|
||||||
const result = await service.getGroupsByTeamId({ teamId: TEAM_ID });
|
|
||||||
expect(result).toEqual(["group1", "group2"]);
|
|
||||||
expect(monitorsRepository.findGroupsByTeamId).toHaveBeenCalledWith(TEAM_ID);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("editMonitor", () => {
|
describe("editMonitor", () => {
|
||||||
it("updates monitor and refreshes job", async () => {
|
it("updates monitor and refreshes job", async () => {
|
||||||
const monitorsRepository = createMonitorsRepositoryMock();
|
const monitorsRepository = createMonitorsRepositoryMock();
|
||||||
|
|||||||
Reference in new issue
Block a user