Skip to content

Commit e42840c

Browse files
issue 2467: add async to send each loop to prevent local validation from throwing in an unknown state (#2469)
Co-authored-by: Lahiru Maramba <llahiru@gmail.com>
1 parent 742cc96 commit e42840c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/messaging/messaging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class Messaging {
294294

295295
return this.getUrlPath()
296296
.then((urlPath) => {
297-
const requests: Promise<SendResponse>[] = copy.map((message) => {
297+
const requests: Promise<SendResponse>[] = copy.map(async (message) => {
298298
validateMessage(message);
299299
const request: { message: Message; validate_only?: boolean } = { message };
300300
if (dryRun) {

test/unit/messaging/messaging.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,19 @@ describe('Messaging', () => {
604604
.should.eventually.be.rejectedWith('Exactly one of topic, token or condition is required');
605605
});
606606

607+
it('should reject a message when it does not pass local validation, but still try the other messages', () => {
608+
const invalidMessage: Message = { token: 'a', notification: { imageUrl: 'abc' } };
609+
const messageIds = [
610+
'projects/projec_id/messages/1',
611+
];
612+
messageIds.forEach(id => mockedRequests.push(mockSendRequest(id)))
613+
return messaging.sendEach([invalidMessage, validMessage])
614+
.then((response: BatchResponse) => {
615+
expect(response.successCount).to.equal(1);
616+
expect(response.failureCount).to.equal(1);
617+
});
618+
});
619+
607620
const invalidDryRun = [null, NaN, 0, 1, '', 'a', [], [1, 'a'], {}, { a: 1 }, _.noop];
608621
invalidDryRun.forEach((dryRun) => {
609622
it(`should throw given invalid dryRun parameter: ${JSON.stringify(dryRun)}`, () => {

0 commit comments

Comments
 (0)