mirror of https://github.com/openclaw/openclaw.git
refactor: share net and slack input helpers
This commit is contained in:
parent
b5eb329f94
commit
854df8352c
|
|
@ -128,12 +128,16 @@ function normalizeIpv4MappedAddress(address: ParsedIpAddress): ParsedIpAddress {
|
|||
return address.toIPv4Address();
|
||||
}
|
||||
|
||||
export function parseCanonicalIpAddress(raw: string | undefined): ParsedIpAddress | undefined {
|
||||
function normalizeIpParseInput(raw: string | undefined): string | undefined {
|
||||
const trimmed = raw?.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const normalized = stripIpv6Brackets(trimmed);
|
||||
return stripIpv6Brackets(trimmed);
|
||||
}
|
||||
|
||||
export function parseCanonicalIpAddress(raw: string | undefined): ParsedIpAddress | undefined {
|
||||
const normalized = normalizeIpParseInput(raw);
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
@ -150,11 +154,7 @@ export function parseCanonicalIpAddress(raw: string | undefined): ParsedIpAddres
|
|||
}
|
||||
|
||||
export function parseLooseIpAddress(raw: string | undefined): ParsedIpAddress | undefined {
|
||||
const trimmed = raw?.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const normalized = stripIpv6Brackets(trimmed);
|
||||
const normalized = normalizeIpParseInput(raw);
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,20 @@ function createHandlerWithTracker(overrides?: {
|
|||
return { handler, trackEvent };
|
||||
}
|
||||
|
||||
async function handleDirectMessage(
|
||||
handler: ReturnType<typeof createHandlerWithTracker>["handler"],
|
||||
) {
|
||||
await handler(
|
||||
{
|
||||
type: "message",
|
||||
channel: "D1",
|
||||
ts: "123.456",
|
||||
text: "hello",
|
||||
} as never,
|
||||
{ source: "message" },
|
||||
);
|
||||
}
|
||||
|
||||
describe("createSlackMessageHandler", () => {
|
||||
beforeEach(() => {
|
||||
enqueueMock.mockClear();
|
||||
|
|
@ -82,15 +96,7 @@ describe("createSlackMessageHandler", () => {
|
|||
it("does not track duplicate messages that are already seen", async () => {
|
||||
const { handler, trackEvent } = createHandlerWithTracker({ markMessageSeen: () => true });
|
||||
|
||||
await handler(
|
||||
{
|
||||
type: "message",
|
||||
channel: "D1",
|
||||
ts: "123.456",
|
||||
text: "hello",
|
||||
} as never,
|
||||
{ source: "message" },
|
||||
);
|
||||
await handleDirectMessage(handler);
|
||||
|
||||
expect(trackEvent).not.toHaveBeenCalled();
|
||||
expect(resolveThreadTsMock).not.toHaveBeenCalled();
|
||||
|
|
@ -100,15 +106,7 @@ describe("createSlackMessageHandler", () => {
|
|||
it("tracks accepted non-duplicate messages", async () => {
|
||||
const { handler, trackEvent } = createHandlerWithTracker();
|
||||
|
||||
await handler(
|
||||
{
|
||||
type: "message",
|
||||
channel: "D1",
|
||||
ts: "123.456",
|
||||
text: "hello",
|
||||
} as never,
|
||||
{ source: "message" },
|
||||
);
|
||||
await handleDirectMessage(handler);
|
||||
|
||||
expect(trackEvent).toHaveBeenCalledTimes(1);
|
||||
expect(resolveThreadTsMock).toHaveBeenCalledTimes(1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue