-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(fcm): Fix error throw when data property exists but is undefined #1139
base: master
Are you sure you want to change the base?
fix(fcm): Fix error throw when data property exists but is undefined #1139
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
This has recently happened to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. This PR somehow slipped through the cracks. It looks mostly good, but some of the tests are not relevant to the fix. And the others require some assertions. I can take another look, if those issues are addressed.
@@ -857,7 +857,7 @@ export class Messaging implements MessagingInterface { | |||
} | |||
|
|||
// Validate the data payload object does not contain blacklisted properties | |||
if ('data' in payloadCopy) { | |||
if ('data' in payloadCopy && payloadCopy.data !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be just if (payloadCopy.data)
@@ -566,6 +566,12 @@ describe('Messaging', () => { | |||
{ token: 'mock-token' }, | |||
).should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-argument'); | |||
}); | |||
|
|||
it('should not throws when the payload contains the data property with undefined value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not throw when
@@ -566,6 +566,12 @@ describe('Messaging', () => { | |||
{ token: 'mock-token' }, | |||
).should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-argument'); | |||
}); | |||
|
|||
it('should not throws when the payload contains the data property with undefined value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case is actually irrelevant to the actual fix. The fix only applies to legacy FCM APIs like sendToDevice()
. It has no effect on send()
. We can remove this.
@@ -823,6 +829,29 @@ describe('Messaging', () => { | |||
[validMessage], | |||
).should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); | |||
}); | |||
|
|||
it('should not throws when the payload contains the data property with undefined value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. Not relevant to the fix.
@@ -1118,6 +1147,31 @@ describe('Messaging', () => { | |||
).should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); | |||
}); | |||
|
|||
it('should not throws when the payload contains the data property with undefined value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
@@ -1457,6 +1511,16 @@ describe('Messaging', () => { | |||
expect(mockOptionsClone).to.deep.equal(mocks.messaging.options); | |||
}); | |||
}); | |||
|
|||
it('should not throws when the payload contains the data property with undefined value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not throw when...
mocks.messaging.registrationToken, | ||
{ ...mocks.messaging.payload, data: undefined }, | ||
mocks.messaging.options, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an assertion here. May be at least .should.eventually.be.fulfilled
.
Hey @hiranya911, Is this PR still need a fix? |
When use
messaging().sendToDevice(tokens, payload)
where payload contains thedata
property, but it's containsundefined
value, I given throws the follow error:The following Pull Request contains the solution of the issue with the covered unit tests.