From 53afef54e5140e7da3a73c9add5f7a4025670639 Mon Sep 17 00:00:00 2001 From: Jeff Bocala Date: Thu, 22 Aug 2019 13:06:21 +1000 Subject: [PATCH 1/2] Wait for APNs response before resolving --- src/template.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/template.ts b/src/template.ts index e54dcdf2..41173f77 100644 --- a/src/template.ts +++ b/src/template.ts @@ -329,8 +329,11 @@ export class Template extends PassBase { // Error handling req.once('error', reject); + // Wait for response before resolving + req.once('response', resolve); + // Post payload (always empty in our case) - req.end('{}', resolve); + req.end('{}'); }); } From 1abac34d8ae7312ffb74acda0b6421675f020cc9 Mon Sep 17 00:00:00 2001 From: Jeff Bocala Date: Thu, 22 Aug 2019 15:09:52 +1000 Subject: [PATCH 2/2] Fix test for template.pushUpdates method --- __tests__/template.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/__tests__/template.ts b/__tests__/template.ts index 27dcdc9e..ea99d45c 100644 --- a/__tests__/template.ts +++ b/__tests__/template.ts @@ -87,13 +87,11 @@ describe('Template', () => { template.pushUpdates( '0e40d22a36e101a59ab296d9e6021df3ee1dcf95e29e8ab432213b12ba522dbb', ), - ).resolves.toBeUndefined(); - // if (template.apn) template.apn.destroy(); - // expect(res).toEqual( - // expect.objectContaining({ - // ':status': 200, - // 'apns-id': expect.any(String), - // }), - // ); + ).resolves.toEqual( + expect.objectContaining({ + ':status': 200, + 'apns-id': expect.any(String), + }), + ); }, 7000); });