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

New send notification #218

Merged
merged 12 commits into from
Sep 20, 2016
Merged

Conversation

gauntface
Copy link

Fixes #192, #216, #184, #200

@marco-c sorry that this is such a large set of changes.

Found a couple of issues in the sendNotification tests, I've re-organised the code a little to be easier to separate concerns a bit more and added a few simple error checks to catch errors earlier on.

marco-c and others added 3 commits September 17, 2016 18:12
# The first commit's message is:

Changes to new API surface for sendNotification

# This is the 2nd commit message:

Add more files to .npmignore
@@ -63,4 +66,7 @@ webPush.sendNotification(endpoint, params).then(() => {
}).then(() => {
process.exit(0);
});
<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from merge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

const ece = require('http_ece');
const urlBase64 = require('urlsafe-base64');

// New standard, Firefox 46+ and Chrome 50+.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I guess we could remove this comment now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@gauntface
Copy link
Author

@marco-c good news, got FF running on Linux and OS X without the GH_TOKEN.


/**
* This method takes the required VAPID parameters and returns the required
* header to added to a Web Push Protocol Request.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: to be added

/**
* This method takes the required VAPID parameters and returns the required
* header to added to a Web Push Protocol Request.
* @param {string} audience This must be the origni of the push service.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: origin

}
}

// Test subscription is an Object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these comments notes for tests that you wanted to write?

requestOptions.headers.Authorization = 'key=' + currentGCMAPIKey;
}
} else if (currentVapidDetails) {
// VAPID isn't supported by GCM.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This comment no longer applies here, should be moved to the if before

});

// TODO:2 good tests for the vapid headers
// TODO: Make sure you can v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this TODO comment is cut 😄

@@ -31,6 +33,13 @@
};
const testDirectory = './test/output/';

webPush.setGCMAPIKey('AIzaSyAwmdX6KKd4hPfIcGU2SOfj9vuRDW6u-wo');
webPush.setVapidDetails(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that we're going to run all tests with vapid, right? Unless you change tests like:

      test('send/receive notification with payload with ' + browser.getPrettyName(), function() {
        this.timeout(PUSH_TEST_TIMEOUT);
        return runTest(browser, {
          payload: 'marco'
        });
});

to:

      test('send/receive notification with payload with ' + browser.getPrettyName(), function() {
        this.timeout(PUSH_TEST_TIMEOUT);
        return runTest(browser, {
          payload: 'marco',
          vapid: null,
        });
});

@@ -163,18 +177,15 @@
}

if (!pushPayload) {
promise = webPush.sendNotification(subscription.endpoint, {
promise = webPush.sendNotification(subscription, null, {
vapid: vapid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be vapidDetails

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. This is exactly the kind of problem I'm trying to avoid :P

I've added an extra check and test to avoid unexpected keys in the extra options.

@@ -25,4 +31,10 @@ suite('setGCMAPIKey', function() {
webPush.setGCMAPIKey(42);
}, Error);
});

test('undefined valud', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: value

@marco-c
Copy link
Member

marco-c commented Sep 19, 2016

@marco-c good news, got FF running on Linux and OS X without the GH_TOKEN.

Great! Are you opening a new PR for that? Or do you want to update this one?

@marco-c
Copy link
Member

marco-c commented Sep 19, 2016

LGTM, just a bunch of nits and a comment regarding the Selenium tests (with the changes we're going to run everything with VAPID, but before we were testing both with and without VAPID).

}

if (!userAuth) {
throw new Error('No user auth provided for encryption.');
}

if (typeof userAuth !== 'string') {
throw new Error('User auth must be a string.');
throw new Error('The subscirption auth key must be a string.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: subscription :)

@marco-c
Copy link
Member

marco-c commented Sep 20, 2016

Oh, we also need to fix the documentation in the README for the new signature.

Copy link
Author

@gauntface gauntface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed all the comments you've raised, thank you so much for the review.

I've changed back to the old way of managing vapid details and that has actually fixed an issue I was seeing on my OS X machine but no where else.

Regarding the README, do you want to update that now or just before we publish this signature?

I expect many developers are using the README for the current API surface.

@@ -163,18 +177,15 @@
}

if (!pushPayload) {
promise = webPush.sendNotification(subscription.endpoint, {
promise = webPush.sendNotification(subscription, null, {
vapid: vapid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. This is exactly the kind of problem I'm trying to avoid :P

I've added an extra check and test to avoid unexpected keys in the extra options.

@gauntface
Copy link
Author

Before changing README and release new version, worth getting #210 and #213 in.

@marco-c
Copy link
Member

marco-c commented Sep 20, 2016

Regarding the README, do you want to update that now or just before we publish this signature?

I expect many developers are using the README for the current API surface.

Before changing README and release new version, worth getting #210 and #213 in.

Good idea, let's change it later.

@marco-c marco-c merged commit 2fcd717 into web-push-libs:master Sep 20, 2016
@marco-c marco-c mentioned this pull request Sep 20, 2016
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.

2 participants