mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 20:12:55 +00:00
test(integration): dedupe messaging, secrets, and plugin test suites
This commit is contained in:
@@ -1,9 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { pruneStickerMediaFromContext } from "./bot-message-dispatch.js";
|
||||
|
||||
type MediaCtx = {
|
||||
MediaPath?: string;
|
||||
MediaUrl?: string;
|
||||
MediaType?: string;
|
||||
MediaPaths?: string[];
|
||||
MediaUrls?: string[];
|
||||
MediaTypes?: string[];
|
||||
};
|
||||
|
||||
function expectSingleImageMedia(ctx: MediaCtx, mediaPath: string) {
|
||||
expect(ctx.MediaPath).toBe(mediaPath);
|
||||
expect(ctx.MediaUrl).toBe(mediaPath);
|
||||
expect(ctx.MediaType).toBe("image/jpeg");
|
||||
expect(ctx.MediaPaths).toEqual([mediaPath]);
|
||||
expect(ctx.MediaUrls).toEqual([mediaPath]);
|
||||
expect(ctx.MediaTypes).toEqual(["image/jpeg"]);
|
||||
}
|
||||
|
||||
describe("pruneStickerMediaFromContext", () => {
|
||||
it("preserves appended reply media while removing primary sticker media", () => {
|
||||
const ctx = {
|
||||
const ctx: MediaCtx = {
|
||||
MediaPath: "/tmp/sticker.webp",
|
||||
MediaUrl: "/tmp/sticker.webp",
|
||||
MediaType: "image/webp",
|
||||
@@ -14,16 +32,11 @@ describe("pruneStickerMediaFromContext", () => {
|
||||
|
||||
pruneStickerMediaFromContext(ctx);
|
||||
|
||||
expect(ctx.MediaPath).toBe("/tmp/replied.jpg");
|
||||
expect(ctx.MediaUrl).toBe("/tmp/replied.jpg");
|
||||
expect(ctx.MediaType).toBe("image/jpeg");
|
||||
expect(ctx.MediaPaths).toEqual(["/tmp/replied.jpg"]);
|
||||
expect(ctx.MediaUrls).toEqual(["/tmp/replied.jpg"]);
|
||||
expect(ctx.MediaTypes).toEqual(["image/jpeg"]);
|
||||
expectSingleImageMedia(ctx, "/tmp/replied.jpg");
|
||||
});
|
||||
|
||||
it("clears media fields when sticker is the only media", () => {
|
||||
const ctx = {
|
||||
const ctx: MediaCtx = {
|
||||
MediaPath: "/tmp/sticker.webp",
|
||||
MediaUrl: "/tmp/sticker.webp",
|
||||
MediaType: "image/webp",
|
||||
@@ -43,7 +56,7 @@ describe("pruneStickerMediaFromContext", () => {
|
||||
});
|
||||
|
||||
it("does not prune when sticker media is already omitted from context", () => {
|
||||
const ctx = {
|
||||
const ctx: MediaCtx = {
|
||||
MediaPath: "/tmp/replied.jpg",
|
||||
MediaUrl: "/tmp/replied.jpg",
|
||||
MediaType: "image/jpeg",
|
||||
@@ -54,11 +67,6 @@ describe("pruneStickerMediaFromContext", () => {
|
||||
|
||||
pruneStickerMediaFromContext(ctx, { stickerMediaIncluded: false });
|
||||
|
||||
expect(ctx.MediaPath).toBe("/tmp/replied.jpg");
|
||||
expect(ctx.MediaUrl).toBe("/tmp/replied.jpg");
|
||||
expect(ctx.MediaType).toBe("image/jpeg");
|
||||
expect(ctx.MediaPaths).toEqual(["/tmp/replied.jpg"]);
|
||||
expect(ctx.MediaUrls).toEqual(["/tmp/replied.jpg"]);
|
||||
expect(ctx.MediaTypes).toEqual(["image/jpeg"]);
|
||||
expectSingleImageMedia(ctx, "/tmp/replied.jpg");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user