diff --git a/src/messaging/messaging.ts b/src/messaging/messaging.ts index 932b8d8e52..f7a2a14ddf 100644 --- a/src/messaging/messaging.ts +++ b/src/messaging/messaging.ts @@ -294,7 +294,7 @@ export class Messaging { return this.getUrlPath() .then((urlPath) => { - const requests: Promise[] = copy.map((message) => { + const requests: Promise[] = copy.map(async (message) => { validateMessage(message); const request: { message: Message; validate_only?: boolean } = { message }; if (dryRun) { diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index dc978c7866..c343ea319d 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -604,6 +604,19 @@ describe('Messaging', () => { .should.eventually.be.rejectedWith('Exactly one of topic, token or condition is required'); }); + it('should reject a message when it does not pass local validation, but still try the other messages', () => { + const invalidMessage: Message = { token: 'a', notification: { imageUrl: 'abc' } }; + const messageIds = [ + 'projects/projec_id/messages/1', + ]; + messageIds.forEach(id => mockedRequests.push(mockSendRequest(id))) + return messaging.sendEach([invalidMessage, validMessage]) + .then((response: BatchResponse) => { + expect(response.successCount).to.equal(1); + expect(response.failureCount).to.equal(1); + }); + }); + const invalidDryRun = [null, NaN, 0, 1, '', 'a', [], [1, 'a'], {}, { a: 1 }, _.noop]; invalidDryRun.forEach((dryRun) => { it(`should throw given invalid dryRun parameter: ${JSON.stringify(dryRun)}`, () => {