Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

italoiz
Copy link

@italoiz italoiz commented Jan 20, 2021

When use messaging().sendToDevice(tokens, payload) where payload contains the data property, but it's contains undefined value, I given throws the follow error:

TypeError: Cannot use 'in' operator to search for 'from' in undefined

The following Pull Request contains the solution of the issue with the covered unit tests.

@google-cla
Copy link

google-cla bot commented Jan 20, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@italoiz
Copy link
Author

italoiz commented Jan 20, 2021

@googlebot I signed it!

@aprilmintacpineda
Copy link

This has recently happened to me.

Copy link
Contributor

@hiranya911 hiranya911 left a 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) {
Copy link
Contributor

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', () => {
Copy link
Contributor

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', () => {
Copy link
Contributor

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', () => {
Copy link
Contributor

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', () => {
Copy link
Contributor

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', () => {
Copy link
Contributor

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,
);
Copy link
Contributor

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.

@hiranya911 hiranya911 changed the title fix(messaging): Fix error throw when data property exists but is undefined fix(fcm): Fix error throw when data property exists but is undefined May 27, 2021
@italoiz
Copy link
Author

italoiz commented Mar 21, 2023

Hey @hiranya911, Is this PR still need a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants