Skip to content

Commit

Permalink
Readable message for watch command when list is already watched.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Nov 29, 2024
1 parent 7280893 commit 3984bfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/commands/WatchUnwatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
describeCommand,
tuple,
} from "@the-draupnir-project/interface-manager";
import { Result } from "@gnuxie/typescript-result";
import { Result, ResultError } from "@gnuxie/typescript-result";
import { Draupnir } from "../Draupnir";
import {
DraupnirContextToCommandContextTranslator,
Expand Down Expand Up @@ -49,6 +49,14 @@ export const DraupnirWatchPolicyRoomCommand = describeCommand({
if (isError(policyRoom)) {
return policyRoom;
}
if (
issuerManager.allWatchedLists.some(
(profile) =>
profile.room.toRoomIDOrAlias() === policyRoom.ok.toRoomIDOrAlias()
)
) {
return ResultError.Result("We are already watching this list.");
}
return await issuerManager.watchList(
PropagationType.Direct,
policyRoom.ok,
Expand Down
15 changes: 15 additions & 0 deletions test/unit/commands/WatchUnwatchCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PolicyListConfig,
PropagationType,
RoomResolver,
isError,
isOk,
} from "matrix-protection-suite";
import { createMock } from "ts-auto-mock";
Expand Down Expand Up @@ -50,6 +51,20 @@ describe("Test the WatchUnwatchCommmands", function () {
);
expect(isOk(result)).toBe(true);
});
it("Draupnir watch command should return an error if the room is already being watched", async function () {
const issuerManagerWithWatchedList = createMock<PolicyListConfig>({
allWatchedLists: [
{ room: policyRoom, propagation: PropagationType.Direct, options: {} },
],
});
const result = await CommandExecutorHelper.execute(
DraupnirWatchPolicyRoomCommand,
{ issuerManager: issuerManagerWithWatchedList, roomResolver },
{},
policyRoom
);
expect(isError(result)).toBe(true);
});
it("DraupnirUnwatchCommand", async function () {
const result = await CommandExecutorHelper.execute(
DraupnirUnwatchPolicyRoomCommand,
Expand Down

0 comments on commit 3984bfa

Please sign in to comment.