Skip to content

Commit bcdefd4

Browse files
authored
Using the correct message copies in sendAll() API (#480)
1 parent 69262ad commit bcdefd4

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

3-
-
3+
- [fixed] Fixed a bug in the FCM batch APIs that prevented them from correctly
4+
handling some message parameters like `AndroidConfig.ttl`.
45

56
# v7.1.0
67

src/messaging/messaging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class Messaging implements FirebaseServiceInterface {
306306
MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
307307
}
308308

309-
const requests: SubRequest[] = messages.map((message) => {
309+
const requests: SubRequest[] = copy.map((message) => {
310310
validateMessage(message);
311311
const request: {message: Message, validate_only?: boolean} = {message};
312312
if (dryRun) {

test/unit/messaging/messaging.spec.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -873,16 +873,22 @@ describe('Messaging', () => {
873873
'projects/projec_id/messages/3',
874874
];
875875
mockedRequests.push(mockBatchRequest(messageIds));
876-
return messaging.sendMulticast({tokens: ['a', 'b', 'c']})
877-
.then((response: BatchResponse) => {
878-
expect(response.successCount).to.equal(3);
879-
expect(response.failureCount).to.equal(0);
880-
response.responses.forEach((resp, idx) => {
881-
expect(resp.success).to.be.true;
882-
expect(resp.messageId).to.equal(messageIds[idx]);
883-
expect(resp.error).to.be.undefined;
884-
});
876+
return messaging.sendMulticast({
877+
tokens: ['a', 'b', 'c'],
878+
android: {ttl: 100},
879+
apns: {payload: {aps: {badge: 42}}},
880+
data: {key: 'value'},
881+
notification: {title: 'test title'},
882+
webpush: {data: {webKey: 'webValue'}},
883+
}).then((response: BatchResponse) => {
884+
expect(response.successCount).to.equal(3);
885+
expect(response.failureCount).to.equal(0);
886+
response.responses.forEach((resp, idx) => {
887+
expect(resp.success).to.be.true;
888+
expect(resp.messageId).to.equal(messageIds[idx]);
889+
expect(resp.error).to.be.undefined;
885890
});
891+
});
886892
});
887893

888894
it('should be fulfilled with a BatchResponse given valid message in dryRun mode', () => {
@@ -892,15 +898,21 @@ describe('Messaging', () => {
892898
'projects/projec_id/messages/3',
893899
];
894900
mockedRequests.push(mockBatchRequest(messageIds));
895-
return messaging.sendMulticast({tokens: ['a', 'b', 'c']}, true)
896-
.then((response: BatchResponse) => {
897-
expect(response.successCount).to.equal(3);
898-
expect(response.failureCount).to.equal(0);
899-
expect(response.responses.length).to.equal(3);
900-
response.responses.forEach((resp, idx) => {
901-
checkSendResponseSuccess(resp, messageIds[idx]);
902-
});
901+
return messaging.sendMulticast({
902+
tokens: ['a', 'b', 'c'],
903+
android: {ttl: 100},
904+
apns: {payload: {aps: {badge: 42}}},
905+
data: {key: 'value'},
906+
notification: {title: 'test title'},
907+
webpush: {data: {webKey: 'webValue'}},
908+
}, true).then((response: BatchResponse) => {
909+
expect(response.successCount).to.equal(3);
910+
expect(response.failureCount).to.equal(0);
911+
expect(response.responses.length).to.equal(3);
912+
response.responses.forEach((resp, idx) => {
913+
checkSendResponseSuccess(resp, messageIds[idx]);
903914
});
915+
});
904916
});
905917

906918
it('should be fulfilled with a BatchResponse when the response contains some errors', () => {

0 commit comments

Comments
 (0)