Skip to content

Commit

Permalink
Using the correct message copies in sendAll() API (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiranya911 authored Mar 18, 2019
1 parent 69262ad commit bcdefd4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

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

# v7.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/messaging/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class Messaging implements FirebaseServiceInterface {
MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
}

const requests: SubRequest[] = messages.map((message) => {
const requests: SubRequest[] = copy.map((message) => {
validateMessage(message);
const request: {message: Message, validate_only?: boolean} = {message};
if (dryRun) {
Expand Down
46 changes: 29 additions & 17 deletions test/unit/messaging/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,16 +873,22 @@ describe('Messaging', () => {
'projects/projec_id/messages/3',
];
mockedRequests.push(mockBatchRequest(messageIds));
return messaging.sendMulticast({tokens: ['a', 'b', 'c']})
.then((response: BatchResponse) => {
expect(response.successCount).to.equal(3);
expect(response.failureCount).to.equal(0);
response.responses.forEach((resp, idx) => {
expect(resp.success).to.be.true;
expect(resp.messageId).to.equal(messageIds[idx]);
expect(resp.error).to.be.undefined;
});
return messaging.sendMulticast({
tokens: ['a', 'b', 'c'],
android: {ttl: 100},
apns: {payload: {aps: {badge: 42}}},
data: {key: 'value'},
notification: {title: 'test title'},
webpush: {data: {webKey: 'webValue'}},
}).then((response: BatchResponse) => {
expect(response.successCount).to.equal(3);
expect(response.failureCount).to.equal(0);
response.responses.forEach((resp, idx) => {
expect(resp.success).to.be.true;
expect(resp.messageId).to.equal(messageIds[idx]);
expect(resp.error).to.be.undefined;
});
});
});

it('should be fulfilled with a BatchResponse given valid message in dryRun mode', () => {
Expand All @@ -892,15 +898,21 @@ describe('Messaging', () => {
'projects/projec_id/messages/3',
];
mockedRequests.push(mockBatchRequest(messageIds));
return messaging.sendMulticast({tokens: ['a', 'b', 'c']}, true)
.then((response: BatchResponse) => {
expect(response.successCount).to.equal(3);
expect(response.failureCount).to.equal(0);
expect(response.responses.length).to.equal(3);
response.responses.forEach((resp, idx) => {
checkSendResponseSuccess(resp, messageIds[idx]);
});
return messaging.sendMulticast({
tokens: ['a', 'b', 'c'],
android: {ttl: 100},
apns: {payload: {aps: {badge: 42}}},
data: {key: 'value'},
notification: {title: 'test title'},
webpush: {data: {webKey: 'webValue'}},
}, true).then((response: BatchResponse) => {
expect(response.successCount).to.equal(3);
expect(response.failureCount).to.equal(0);
expect(response.responses.length).to.equal(3);
response.responses.forEach((resp, idx) => {
checkSendResponseSuccess(resp, messageIds[idx]);
});
});
});

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

0 comments on commit bcdefd4

Please sign in to comment.