mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-18 05:23:39 +02:00
Add dormant provider contracts, qualified patched adapters, tenant-scoped persistence and lifecycle ownership without activating chat routes. Preserve the experimental integration as dependent PR #13038. Co-Authored-By: Paperclip <noreply@paperclip.ing>
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
telegramStopSubscriptionPlan,
|
|
telegramStopSubscriptionConfirmed,
|
|
} from "./chat-telegram-stop-subscription.js";
|
|
|
|
describe("Telegram Stop subscription preservation", () => {
|
|
const url = "https://example.test/api/chat-webhooks/fixture/telegram";
|
|
const info = {
|
|
url,
|
|
has_custom_certificate: false,
|
|
max_connections: 37,
|
|
pending_update_count: 99,
|
|
ip_address: "203.0.113.4",
|
|
};
|
|
it.each([undefined, []])(
|
|
"preserves default subscriptions explicitly (%s)",
|
|
(allowed_updates) => {
|
|
expect(
|
|
telegramStopSubscriptionPlan({ ...info, allowed_updates }, url),
|
|
).toEqual({ allowed_updates: [], max_connections: 37 });
|
|
},
|
|
);
|
|
it("preserves opt-ins and unknown future names without copying routing diagnostics", () => {
|
|
expect(
|
|
telegramStopSubscriptionPlan(
|
|
{ ...info, allowed_updates: ["message_reaction", "future_update"] },
|
|
url,
|
|
),
|
|
).toEqual({
|
|
allowed_updates: [
|
|
"message_reaction",
|
|
"future_update",
|
|
"stopped_message_generation",
|
|
],
|
|
max_connections: 37,
|
|
});
|
|
});
|
|
it("never upgrades a contradictory final observation into a confirmation", () => {
|
|
const before = { ...info, allowed_updates: ["message"] };
|
|
const plan = telegramStopSubscriptionPlan(before, url)!;
|
|
expect(telegramStopSubscriptionConfirmed(before, url, plan)).toBe(false);
|
|
expect(
|
|
telegramStopSubscriptionConfirmed(
|
|
{ ...info, allowed_updates: plan.allowed_updates },
|
|
url,
|
|
plan,
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
telegramStopSubscriptionConfirmed(
|
|
{ ...info, allowed_updates: [...plan.allowed_updates].reverse() },
|
|
url,
|
|
plan,
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
telegramStopSubscriptionConfirmed(
|
|
{ ...info, allowed_updates: [...plan.allowed_updates, "message"] },
|
|
url,
|
|
plan,
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
telegramStopSubscriptionConfirmed(info, url, {
|
|
allowed_updates: [],
|
|
max_connections: 37,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
it.each([
|
|
null,
|
|
[],
|
|
{},
|
|
{ ...info, url: "https://other.test/" },
|
|
{ ...info, has_custom_certificate: true },
|
|
{ ...info, has_custom_certificate: undefined },
|
|
{ ...info, max_connections: 0 },
|
|
{ ...info, max_connections: 101 },
|
|
{ ...info, max_connections: "37" },
|
|
{ ...info, allowed_updates: "message" },
|
|
{ ...info, allowed_updates: [1] },
|
|
{ ...info, allowed_updates: null },
|
|
{ ...info, max_connections: null },
|
|
{ ...info, allowed_updates: ["private\nvalue"] },
|
|
{ ...info, allowed_updates: Array(257).fill("message") },
|
|
])("refuses unsupported or malformed preservation %j", (value) => {
|
|
expect(telegramStopSubscriptionPlan(value, url)).toBeNull();
|
|
});
|
|
});
|