























@@ -6,17 +6,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66import webPush from "web-push";
77import {
88broadcastWebPush,
9-clearWebPushSubscription,
109clearWebPushSubscriptionByEndpoint,
1110listWebPushSubscriptions,
12-loadWebPushSubscription,
1311registerWebPushSubscription,
1412resolveVapidKeys,
1513sendWebPushNotification,
1614} from "./push-web.js";
171518-type WebPushSubscription = NonNullable<Awaited<ReturnType<typeof loadWebPushSubscription>>>;
19-2016// Stub resolveStateDir so tests use a temp directory.
2117let tmpDir: string;
2218vi.mock("../config/paths.js", () => ({
@@ -35,16 +31,6 @@ vi.mock("web-push", () => ({
3531},
3632}));
373338-function expectLoadedSubscription(
39-loaded: Awaited<ReturnType<typeof loadWebPushSubscription>>,
40-): WebPushSubscription {
41-if (loaded === null) {
42-throw new Error("Expected loaded web push subscription");
43-}
44-expect(loaded.endpoint).not.toBe("");
45-return loaded;
46-}
47-4834beforeEach(async () => {
4935tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "push-web-test-"));
5036vi.clearAllMocks();
@@ -128,21 +114,6 @@ describe("subscription CRUD", () => {
128114expect(sub2.keys.p256dh).toBe("new-p256dh");
129115});
130116131-it("loads a subscription by ID", async () => {
132-const sub = await registerWebPushSubscription({
133- endpoint,
134- keys,
135-baseDir: tmpDir,
136-});
137-const loaded = await loadWebPushSubscription(sub.subscriptionId, tmpDir);
138-expect(expectLoadedSubscription(loaded).endpoint).toBe(endpoint);
139-});
140-141-it("returns null for unknown subscription ID", async () => {
142-const loaded = await loadWebPushSubscription("nonexistent", tmpDir);
143-expect(loaded).toBeNull();
144-});
145-146117it("lists all subscriptions", async () => {
147118await registerWebPushSubscription({
148119endpoint: "https://push.example.com/a",
@@ -158,19 +129,6 @@ describe("subscription CRUD", () => {
158129expect(list).toHaveLength(2);
159130});
160131161-it("clears a subscription by ID", async () => {
162-const sub = await registerWebPushSubscription({
163- endpoint,
164- keys,
165-baseDir: tmpDir,
166-});
167-const removed = await clearWebPushSubscription(sub.subscriptionId, tmpDir);
168-expect(removed).toBe(true);
169-170-const list = await listWebPushSubscriptions(tmpDir);
171-expect(list).toHaveLength(0);
172-});
173-174132it("clears a subscription by endpoint", async () => {
175133await registerWebPushSubscription({ endpoint, keys, baseDir: tmpDir });
176134const removed = await clearWebPushSubscriptionByEndpoint(endpoint, tmpDir);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。