Skip to content

Commit 630f0d6

Browse files
committed
refactor: share push test response assertions
1 parent 6173a4b commit 630f0d6

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ function firstRespondCall(respond: ReturnType<typeof vi.fn>): RespondCall | unde
121121
return respond.mock.calls[0] as RespondCall | undefined;
122122
}
123123

124+
function expectSuccessfulPushTestResponse(respond: ReturnType<typeof vi.fn>): ApnsPushResult {
125+
expect(sendApnsAlert).toHaveBeenCalledTimes(1);
126+
const call = firstRespondCall(respond);
127+
expect(call?.[0]).toBe(true);
128+
const result = call?.[1] as ApnsPushResult | undefined;
129+
expect(result?.ok).toBe(true);
130+
expect(result?.status).toBe(200);
131+
return result as ApnsPushResult;
132+
}
133+
124134
describe("push.test handler", () => {
125135
beforeEach(() => {
126136
mocks.getRuntimeConfig.mockClear();
@@ -160,12 +170,7 @@ describe("push.test handler", () => {
160170
});
161171
await invoke();
162172

163-
expect(sendApnsAlert).toHaveBeenCalledTimes(1);
164-
const call = firstRespondCall(respond);
165-
expect(call?.[0]).toBe(true);
166-
const result = call?.[1] as ApnsPushResult | undefined;
167-
expect(result?.ok).toBe(true);
168-
expect(result?.status).toBe(200);
173+
expectSuccessfulPushTestResponse(respond);
169174
});
170175

171176
it("sends push test through relay registrations", async () => {
@@ -223,12 +228,7 @@ describe("push.test handler", () => {
223228
},
224229
{ registrationRelayOrigin: undefined },
225230
);
226-
expect(sendApnsAlert).toHaveBeenCalledTimes(1);
227-
const call = firstRespondCall(respond);
228-
expect(call?.[0]).toBe(true);
229-
const result = call?.[1] as ApnsPushResult | undefined;
230-
expect(result?.ok).toBe(true);
231-
expect(result?.status).toBe(200);
231+
const result = expectSuccessfulPushTestResponse(respond);
232232
expect(result?.transport).toBe("relay");
233233
});
234234

0 commit comments

Comments
 (0)