From 2c5290a7b116c75f278fed342d67461f0ac47273 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 17:57:42 +0100 Subject: [PATCH] test(gateway): share paired ios operator fixture --- src/gateway/exec-approval-ios-push.test.ts | 117 +++++---------------- 1 file changed, 29 insertions(+), 88 deletions(-) diff --git a/src/gateway/exec-approval-ios-push.test.ts b/src/gateway/exec-approval-ios-push.test.ts index 820dce2eb46..faf0c681fc0 100644 --- a/src/gateway/exec-approval-ios-push.test.ts +++ b/src/gateway/exec-approval-ios-push.test.ts @@ -23,6 +23,31 @@ function createDeferred(): Deferred { return { promise, resolve, reject }; } +function mockPairedIosOperator(scopes: string[]) { + listDevicePairingMock.mockResolvedValue({ + pending: [], + paired: [ + { + deviceId: "ios-device-1", + publicKey: "pub", + platform: "iOS 18", + role: "operator", + roles: ["operator"], + createdAtMs: 1, + approvedAtMs: 1, + tokens: { + operator: { + token: "operator-token", + role: "operator", + scopes, + createdAtMs: 1, + }, + }, + }, + ], + }); +} + vi.mock("../config/config.js", () => ({ loadConfig: () => ({ gateway: {} }), })); @@ -124,28 +149,7 @@ describe("createExecApprovalIosPushDelivery", () => { }); it("targets iOS devices when the active operator token includes operator.approvals", async () => { - listDevicePairingMock.mockResolvedValue({ - pending: [], - paired: [ - { - deviceId: "ios-device-1", - publicKey: "pub", - platform: "iOS 18", - role: "operator", - roles: ["operator"], - createdAtMs: 1, - approvedAtMs: 1, - tokens: { - operator: { - token: "operator-token", - role: "operator", - scopes: ["operator.approvals", "operator.read"], - createdAtMs: 1, - }, - }, - }, - ], - }); + mockPairedIosOperator(["operator.approvals", "operator.read"]); const { createExecApprovalIosPushDelivery } = await import("./exec-approval-ios-push.js"); const delivery = createExecApprovalIosPushDelivery({ log: {} }); @@ -164,28 +168,7 @@ describe("createExecApprovalIosPushDelivery", () => { it("does not treat iOS as a live approval route when every push fails", async () => { const warn = vi.fn(); - listDevicePairingMock.mockResolvedValue({ - pending: [], - paired: [ - { - deviceId: "ios-device-1", - publicKey: "pub", - platform: "iOS 18", - role: "operator", - roles: ["operator"], - createdAtMs: 1, - approvedAtMs: 1, - tokens: { - operator: { - token: "operator-token", - role: "operator", - scopes: ["operator.approvals", "operator.read"], - createdAtMs: 1, - }, - }, - }, - ], - }); + mockPairedIosOperator(["operator.approvals", "operator.read"]); sendApnsExecApprovalAlertMock.mockResolvedValue({ ok: false, status: 410, @@ -217,28 +200,7 @@ describe("createExecApprovalIosPushDelivery", () => { }); it("waits for request delivery to finish before sending cleanup pushes", async () => { - listDevicePairingMock.mockResolvedValue({ - pending: [], - paired: [ - { - deviceId: "ios-device-1", - publicKey: "pub", - platform: "iOS 18", - role: "operator", - roles: ["operator"], - createdAtMs: 1, - approvedAtMs: 1, - tokens: { - operator: { - token: "operator-token", - role: "operator", - scopes: ["operator.approvals", "operator.read"], - createdAtMs: 1, - }, - }, - }, - ], - }); + mockPairedIosOperator(["operator.approvals", "operator.read"]); const requestedPush = createDeferred<{ ok: boolean; status: number; @@ -301,28 +263,7 @@ describe("createExecApprovalIosPushDelivery", () => { }); it("sends cleanup pushes only to the original request targets", async () => { - listDevicePairingMock.mockResolvedValue({ - pending: [], - paired: [ - { - deviceId: "ios-device-1", - publicKey: "pub", - platform: "iOS 18", - role: "operator", - roles: ["operator"], - createdAtMs: 1, - approvedAtMs: 1, - tokens: { - operator: { - token: "operator-token", - role: "operator", - scopes: ["operator.approvals", "operator.read"], - createdAtMs: 1, - }, - }, - }, - ], - }); + mockPairedIosOperator(["operator.approvals", "operator.read"]); const { createExecApprovalIosPushDelivery } = await import("./exec-approval-ios-push.js"); const delivery = createExecApprovalIosPushDelivery({ log: {} });