|
1 | 1 | // Discord tests cover send.webhook activity plugin behavior. |
| 2 | +import { MessageFlags } from "discord-api-types/v10"; |
2 | 3 | import { isRecentOutboundMessageIdentity } from "openclaw/plugin-sdk/channel-outbound"; |
3 | 4 | import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 5 |
|
@@ -155,9 +156,72 @@ describe("sendWebhookMessageDiscord activity", () => { |
155 | 156 | }, |
156 | 157 | body: JSON.stringify({ |
157 | 158 | content: "hello <@123456789012345678>", |
| 159 | + flags: MessageFlags.SuppressEmbeds, |
158 | 160 | }), |
159 | 161 | signal: expect.any(AbortSignal), |
160 | 162 | }, |
161 | 163 | ]); |
162 | 164 | }); |
| 165 | + |
| 166 | + it.each([ |
| 167 | + { |
| 168 | + name: "the default", |
| 169 | + channelSuppressEmbeds: undefined, |
| 170 | + accountSuppressEmbeds: undefined, |
| 171 | + expectedFlags: MessageFlags.SuppressEmbeds, |
| 172 | + }, |
| 173 | + { |
| 174 | + name: "the channel opt-out", |
| 175 | + channelSuppressEmbeds: false, |
| 176 | + accountSuppressEmbeds: undefined, |
| 177 | + expectedFlags: undefined, |
| 178 | + }, |
| 179 | + { |
| 180 | + name: "an account opt-out", |
| 181 | + channelSuppressEmbeds: true, |
| 182 | + accountSuppressEmbeds: false, |
| 183 | + expectedFlags: undefined, |
| 184 | + }, |
| 185 | + { |
| 186 | + name: "an account opt-in", |
| 187 | + channelSuppressEmbeds: false, |
| 188 | + accountSuppressEmbeds: true, |
| 189 | + expectedFlags: MessageFlags.SuppressEmbeds, |
| 190 | + }, |
| 191 | + ])( |
| 192 | + "applies $name for webhook link-preview suppression", |
| 193 | + async ({ channelSuppressEmbeds, accountSuppressEmbeds, expectedFlags }) => { |
| 194 | + const cfg = { |
| 195 | + channels: { |
| 196 | + discord: { |
| 197 | + token: "resolved-token", |
| 198 | + ...(channelSuppressEmbeds === undefined |
| 199 | + ? {} |
| 200 | + : { suppressEmbeds: channelSuppressEmbeds }), |
| 201 | + accounts: { |
| 202 | + runtime: |
| 203 | + accountSuppressEmbeds === undefined |
| 204 | + ? {} |
| 205 | + : { suppressEmbeds: accountSuppressEmbeds }, |
| 206 | + }, |
| 207 | + }, |
| 208 | + }, |
| 209 | + }; |
| 210 | + |
| 211 | + await sendWebhookMessageDiscord("https://example.com", { |
| 212 | + cfg, |
| 213 | + webhookId: "wh-1", |
| 214 | + webhookToken: "tok-1", |
| 215 | + accountId: "runtime", |
| 216 | + threadId: "thread-1", |
| 217 | + }); |
| 218 | + |
| 219 | + const request = firstMockCall(vi.mocked(fetch), "fetch")[1] as RequestInit; |
| 220 | + if (typeof request.body !== "string") { |
| 221 | + throw new Error("expected webhook request body"); |
| 222 | + } |
| 223 | + const body = JSON.parse(request.body) as { flags?: number }; |
| 224 | + expect(body.flags).toBe(expectedFlags); |
| 225 | + }, |
| 226 | + ); |
163 | 227 | }); |
0 commit comments