Skip to content

Commit ae9b704

Browse files
committed
test: dedupe gateway push mock reads
1 parent 041906e commit ae9b704

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/gateway/server-methods/push.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,16 @@ function expectInvalidRequestResponse(
111111
respond: ReturnType<typeof vi.fn>,
112112
expectedMessagePart: string,
113113
) {
114-
const call = respond.mock.calls.at(0) as RespondCall | undefined;
114+
const call = firstRespondCall(respond);
115115
expect(call?.[0]).toBe(false);
116116
expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
117117
expect(call?.[2]?.message).toContain(expectedMessagePart);
118118
}
119119

120+
function firstRespondCall(respond: ReturnType<typeof vi.fn>): RespondCall | undefined {
121+
return respond.mock.calls[0] as RespondCall | undefined;
122+
}
123+
120124
describe("push.test handler", () => {
121125
beforeEach(() => {
122126
mocks.getRuntimeConfig.mockClear();
@@ -157,7 +161,7 @@ describe("push.test handler", () => {
157161
await invoke();
158162

159163
expect(sendApnsAlert).toHaveBeenCalledTimes(1);
160-
const call = respond.mock.calls.at(0) as RespondCall | undefined;
164+
const call = firstRespondCall(respond);
161165
expect(call?.[0]).toBe(true);
162166
const result = call?.[1] as ApnsPushResult | undefined;
163167
expect(result?.ok).toBe(true);
@@ -216,7 +220,7 @@ describe("push.test handler", () => {
216220
},
217221
});
218222
expect(sendApnsAlert).toHaveBeenCalledTimes(1);
219-
const call = respond.mock.calls.at(0) as RespondCall | undefined;
223+
const call = firstRespondCall(respond);
220224
expect(call?.[0]).toBe(true);
221225
const result = call?.[1] as ApnsPushResult | undefined;
222226
expect(result?.ok).toBe(true);

0 commit comments

Comments
 (0)