Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readable message for watch command when list is already watched. #631

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading