|
|
|
|
@ -4,9 +4,11 @@ import {
|
|
|
|
|
DEFAULT_ACCOUNT_ID,
|
|
|
|
|
expectPairingPromptSent,
|
|
|
|
|
getAuthDir,
|
|
|
|
|
getMonitorWebInbox,
|
|
|
|
|
getSock,
|
|
|
|
|
installWebMonitorInboxUnitTestHooks,
|
|
|
|
|
mockLoadConfig,
|
|
|
|
|
settleInboundWork,
|
|
|
|
|
} from "./monitor-inbox.test-harness.js";
|
|
|
|
|
|
|
|
|
|
const nowSeconds = (offsetMs = 0) => Math.floor((Date.now() + offsetMs) / 1000);
|
|
|
|
|
@ -19,10 +21,6 @@ const TIMESTAMP_OFF_MESSAGES_CFG = {
|
|
|
|
|
timestampPrefix: false,
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
async function flushInboundQueue() {
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createNotifyUpsert = (message: Record<string, unknown>) => ({
|
|
|
|
|
type: "notify",
|
|
|
|
|
messages: [message],
|
|
|
|
|
@ -58,7 +56,7 @@ async function startWebInboxMonitor(params: {
|
|
|
|
|
config?: Record<string, unknown>;
|
|
|
|
|
sendReadReceipts?: boolean;
|
|
|
|
|
}) {
|
|
|
|
|
const { monitorWebInbox } = await import("./inbound.js");
|
|
|
|
|
const monitorWebInbox = getMonitorWebInbox();
|
|
|
|
|
if (params.config) {
|
|
|
|
|
mockLoadConfig.mockReturnValue(params.config);
|
|
|
|
|
}
|
|
|
|
|
@ -111,7 +109,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
// Should NOT call onMessage for unauthorized senders
|
|
|
|
|
expect(onMessage).not.toHaveBeenCalled();
|
|
|
|
|
@ -147,7 +145,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
expect(onMessage).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(onMessage).toHaveBeenCalledWith(
|
|
|
|
|
@ -172,7 +170,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
expect(onMessage).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(sock.readMessages).not.toHaveBeenCalled();
|
|
|
|
|
@ -197,7 +195,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
expect(onMessage).toHaveBeenCalledTimes(1);
|
|
|
|
|
const payload = onMessage.mock.calls[0][0];
|
|
|
|
|
@ -224,7 +222,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
// Should NOT call onMessage because groupPolicy is disabled
|
|
|
|
|
expect(onMessage).not.toHaveBeenCalled();
|
|
|
|
|
@ -254,7 +252,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
// Should NOT call onMessage because sender +999 not in groupAllowFrom
|
|
|
|
|
expect(onMessage).not.toHaveBeenCalled();
|
|
|
|
|
@ -284,7 +282,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
// Should call onMessage because sender is in groupAllowFrom
|
|
|
|
|
expect(onMessage).toHaveBeenCalledTimes(1);
|
|
|
|
|
@ -318,7 +316,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
// Should call onMessage because wildcard allows all senders
|
|
|
|
|
expect(onMessage).toHaveBeenCalledTimes(1);
|
|
|
|
|
@ -349,7 +347,7 @@ describe("web monitor inbox", () => {
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await flushInboundQueue();
|
|
|
|
|
await settleInboundWork();
|
|
|
|
|
|
|
|
|
|
expect(onMessage).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
|