test: verify teams generated values

This commit is contained in:
Shakker
2026-05-11 16:45:47 +01:00
parent a1fc955aef
commit 2deeb9f668
4 changed files with 11 additions and 13 deletions

View File

@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { PluginRuntime } from "../runtime-api.js";
import { readRemoteMediaResponse } from "./attachments.test-helpers.js";
import { downloadMSTeamsGraphMedia } from "./attachments/graph.js";
import { resolveRequestUrl } from "./attachments/shared.js";
import { encodeGraphShareId, resolveRequestUrl } from "./attachments/shared.js";
import { setMSTeamsRuntime } from "./runtime.js";
const GRAPH_HOST = "graph.microsoft.com";
@@ -316,11 +316,12 @@ describe("msteams graph attachments", () => {
expectAttachmentMediaLength(media.media, 0);
const calledUrls = fetchMock.mock.calls.map((call) => call[0]);
const expectedSharesUrl = `${GRAPH_SHARES_URL_PREFIX}${encodeGraphShareId(DEFAULT_SHARE_REFERENCE_URL)}/driveItem/content`;
expect(calledUrls).toEqual([
DEFAULT_MESSAGE_URL,
expect.stringContaining(GRAPH_SHARES_URL_PREFIX),
expectedSharesUrl,
`${DEFAULT_MESSAGE_URL}/hostedContents`,
expect.stringContaining(GRAPH_SHARES_URL_PREFIX),
expectedSharesUrl,
]);
expect(calledUrls).not.toContain(escapedUrl);
});

View File

@@ -455,20 +455,16 @@ describe("Graph shared-link helpers", () => {
it("tryBuildGraphSharesUrlForSharedLink rewrites SharePoint URLs", () => {
const url = "https://contoso.sharepoint.com/personal/user/Documents/report.pdf";
const result = tryBuildGraphSharesUrlForSharedLink(url);
expect(result).toEqual(
expect.stringMatching(
/^https:\/\/graph\.microsoft\.com\/v1\.0\/shares\/u![A-Za-z0-9_-]+\/driveItem\/content$/,
),
expect(result).toBe(
`https://graph.microsoft.com/v1.0/shares/${encodeGraphShareId(url)}/driveItem/content`,
);
});
it("tryBuildGraphSharesUrlForSharedLink rewrites OneDrive URLs", () => {
const url = "https://1drv.ms/b/s!AkxYabcdefg";
const result = tryBuildGraphSharesUrlForSharedLink(url);
expect(result).toEqual(
expect.stringMatching(
/^https:\/\/graph\.microsoft\.com\/v1\.0\/shares\/u![A-Za-z0-9_-]+\/driveItem\/content$/,
),
expect(result).toBe(
`https://graph.microsoft.com/v1.0/shares/${encodeGraphShareId(url)}/driveItem/content`,
);
});

View File

@@ -5,6 +5,7 @@ import {
uploadToConsentUrl,
validateConsentUploadUrl,
} from "./file-consent.js";
import { buildUserAgent } from "./user-agent.js";
// Helper: a resolveFn that returns a public IP by default
const publicResolve = async () => ({ address: "13.107.136.10" });
@@ -277,7 +278,7 @@ describe("uploadToConsentUrl", () => {
expect(opts?.headers).toEqual({
"Content-Range": "bytes 0-4/5",
"Content-Type": "application/octet-stream",
"User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
"User-Agent": buildUserAgent(),
});
expect(opts?.body).toEqual(new Uint8Array(Buffer.from("hello")));
});

View File

@@ -372,7 +372,7 @@ describe("createMSTeamsReplyDispatcher", () => {
await dispatcher.replyOptions.onToolStart?.({ name: "exec" });
expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenCalledWith(
expect.stringMatching(/^[^\n]+\.\.\.$/),
pickInformativeStatusText({ seed: "default:conv" }),
);
});