diff --git a/README.md b/README.md index 97e25da..5a094f3 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,11 @@ $ npm install node-gcm --save ## Requirements -This library provides the server-side implementation of GCM. -You need to generate an [API Key](https://developers.google.com/cloud-messaging/gcm#apikey). +This library provides the server-side implementation of FCM. +You need to generate an [API Key](https://console.firebase.google.com/u/0/) (Click the gear next to FCM project name) > Project Settings > Cloud Messaging -> **Server Key**). -GCM notifications can be sent to both [Android](https://developers.google.com/cloud-messaging/android/start) and [iOS](https://developers.google.com/cloud-messaging/ios/start). -If you are new to GCM you should probably look into the [documentation](https://developers.google.com/cloud-messaging/gcm). +FCM notifications can be sent to both [Android](https://firebase.google.com/docs/cloud-messaging/android/client) and [iOS](https://firebase.google.com/docs/cloud-messaging/ios/client). +If you are new to FCM you should probably look into the [documentation](https://firebase.google.com/docs/cloud-messaging). ## Example application @@ -128,14 +128,11 @@ sender.send(message, { registrationTokens: registrationTokens }, 10, function (e else console.log(response); }); -// Q: I need to remove all "bad" token from my database, how do I do that? +// Q: I need to remove all "bad" token from my database, how do I do that? // The results-array does not contain any tokens! // A: The array of tokens used for sending will match the array of results, so you can cross-check them. -sender.send(message, { registrationTokens: registrationTokens }, function (err, response) { - var failed_tokens = response.results // Array with result for each token we messaged - .map((res, i) => res.error ? registrationTokens[i] : null) // If there's any kind of error, - // pick _the token_ from the _other_ array - .filter(token => token); // Remove all the null values +sender.send(message, { registrationTokens: registrationTokens }, function (err, response) { + var failed_tokens = registrationTokens.filter((token, i) => response[i].error != null); console.log('These tokens are no longer ok:', failed_tokens); }); ``` @@ -146,7 +143,7 @@ You can send push notifications to various recipient types by providing one of t |Key|Type|Description| |---|---|---| -|to|String|A single [registration token](https://developers.google.com/cloud-messaging/android/client#sample-register), [notification key](https://developers.google.com/cloud-messaging/notifications), or [topic](https://developers.google.com/cloud-messaging/topic-messaging). +|to|String|A single [registration token](https://firebase.google.com/docs/cloud-messaging/android/client#sample-register), [notification key](https://firebase.google.com/docs/cloud-messaging/android/device-group), or [topic](https://firebase.google.com/docs/cloud-messaging/android/topic-messaging). |topic|String|A single publish/subscribe topic. |condition|String|Multiple topics using the [condition](https://firebase.google.com/docs/cloud-messaging/topic-messaging) parameter. |notificationKey|String|Deprecated. A key that groups multiple registration tokens linked to the same user. @@ -156,7 +153,7 @@ You can send push notifications to various recipient types by providing one of t If you provide an incorrect recipient key or object type, an `Error` object will be returned to your callback. Notice that [you can *at most* send notifications to 1000 registration tokens at a time](https://github.com/ToothlessGear/node-gcm/issues/42). -This is due to [a restriction](http://developer.android.com/training/cloudsync/gcm.html) on the side of the GCM API. +This is due to [a restriction](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json) on the side of the FCM API. ### Additional message options @@ -166,11 +163,13 @@ This is due to [a restriction](http://developer.android.com/training/cloudsync/g |collapseKey|Optional, string|This parameter identifies a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed.| |priority|Optional, string|Sets the priority of the message. Valid values are "normal" and "high."| |contentAvailable|Optional, JSON boolean|On iOS, when a notification or message is sent and this is set to true, an inactive client app is awoken.| -|timeToLive|Optional, JSON number|This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks.| +|mutableContent|Optional, JSON boolean|On iOS, Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNs payload. When a notification is sent and this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension.| +|timeToLive|Optional, JSON number|This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks.| |restrictedPackageName|Optional, string|This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.| |dryRun|Optional, JSON boolean|This parameter, when set to true, allows developers to test a request without actually sending a message.| |data|Optional, JSON object|This parameter specifies the custom key-value pairs of the message's payload.| |notification|Optional, JSON object|This parameter specifies the predefined, user-visible key-value pairs of the notification payload. See "Notification payload option table" below for more details.| +|fcm_options|Optional, JSON object|This parameter is used to pass FCM specific options, as outlined [here](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#FcmOptions). ## Notification usage @@ -211,11 +210,11 @@ message.addNotification({ |title_loc_args|iOS|Optional, JSON array as string|Indicates the string value to replace format specifiers in title string for localization. On iOS, this corresponds to "title-loc-args" in APNS payload.| |title_loc_key|iOS|Optional, string|Indicates the key to the title string for localization. On iOS, this corresponds to "title-loc-key" in APNS payload.| -Notice notification payload defined in [GCM Connection Server Reference](https://developers.google.com/cloud-messaging/server-ref#table1) +Notice notification payload defined in [FCM Connection Server Reference](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json) ## Custom HTTP request options -You can provide custom `request` options such as `proxy` and `timeout` for the HTTP request to the GCM API. For more information, refer to [the complete list of request options](https://github.com/request/request#requestoptions-callback). Note that the following options cannot be overriden: `method`, `uri`, `body`, as well as the following headers: `Authorization`, `Content-Type`, and `Content-Length`. +You can provide custom `request` options such as `proxy` and `timeout` for the HTTP request to the FCM API. For more information, refer to [the complete list of request options](https://github.com/request/request#requestoptions-callback). Note that the following options cannot be overriden: `method`, `uri`, `body`, as well as the following headers: `Authorization`, `Content-Type`, and `Content-Length`. ```js // Set custom request options @@ -236,9 +235,9 @@ sender.send(message, { registrationTokens: regTokens }, function (err, response) }); ``` -## GCM client compatibility +## FCM client compatibility -As of January 9th, 2016, there are a few known compatibility issues with 3rd-party GCM client libraries: +As of January 9th, 2016, there are a few known compatibility issues with 3rd-party FCM client libraries: ### phonegap-plugin-push @@ -250,7 +249,7 @@ These issues are out of this project's context and can only be fixed by the resp ## Debug -To enable debug mode (print requests and responses to and from GCM), +To enable debug mode (print requests and responses to and from FCM), set the `DEBUG` environment flag when running your app (assuming you use `node app.js` to run your app): ```bash diff --git a/lib/message-options.js b/lib/message-options.js index 338d3f5..7a93980 100644 --- a/lib/message-options.js +++ b/lib/message-options.js @@ -1,13 +1,13 @@ /** * This module defines all the arguments that may be passed to a message. - * + * * Each argument may contain a field `__argName`, if the name of the field * should be different when sent to the server. - * + * * The argument may also contain a field `__argType`, if the given * argument must be of that type. The types are the strings resulting from * calling `typeof ` where `` is the argument. - * + * * Other than that, the arguments are expected to follow the indicated * structure. */ @@ -51,5 +51,8 @@ module.exports = { __argType: "object" //TODO: There are a lot of very specific arguments that could // be indicated here. + }, + fcm_options: { + __argType: "object" } }; diff --git a/lib/sender.js b/lib/sender.js index 28e6edd..15a8447 100644 --- a/lib/sender.js +++ b/lib/sender.js @@ -148,9 +148,9 @@ Sender.prototype.sendNoRetry = function(message, recipient, callback) { headers: { 'Authorization': 'key=' + this.key }, - uri: Constants.GCM_SEND_URI, json: body }, this.options, { + uri: Constants.GCM_SEND_URI, timeout: Constants.SOCKET_TIMEOUT }); diff --git a/package-lock.json b/package-lock.json index 3568ab8..70bce6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,46 +1,52 @@ { "name": "@parse/node-gcm", - "version": "1.0.2", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { "@sinonjs/commons": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.0.2.tgz", - "integrity": "sha512-WR3dlgqJP4QNrLC4iXN/5/2WaLQQ0VijOOkmflqFGVJ6wLEpbSjo7c0ZeGIdtY8Crk7xBBp87sM6+Mkerz7alw==", + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", + "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==", "dev": true, "requires": { "type-detect": "4.0.8" } }, "@sinonjs/formatio": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.0.0.tgz", - "integrity": "sha512-vdjoYLDptCgvtJs57ULshak3iJe4NW3sJ3g36xVDGff5AE8P30S6A093EIEPjdi2noGhfuNOEkbxt3J3awFW1w==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.2.tgz", + "integrity": "sha512-B8SEsgd8gArBLMD6zpRw3juQ2FVSsmdd7qlevyDqzS9WTCtvF55/gAL+h6gue8ZvPYcdiPdvueM/qm//9XzyTQ==", "dev": true, "requires": { - "@sinonjs/samsam": "2.1.0" + "@sinonjs/commons": "^1", + "@sinonjs/samsam": "^3.1.0" }, "dependencies": { "@sinonjs/samsam": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.0.tgz", - "integrity": "sha512-5x2kFgJYupaF1ns/RmharQ90lQkd2ELS8A9X0ymkAAdemYHGtI2KiUHG8nX2WU0T1qgnOU5YMqnBM2V7NUanNw==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.3.tgz", + "integrity": "sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ==", "dev": true, "requires": { - "array-from": "^2.1.1" + "@sinonjs/commons": "^1.3.0", + "array-from": "^2.1.1", + "lodash": "^4.17.15" } } } }, "@sinonjs/samsam": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.1.tgz", - "integrity": "sha512-7oX6PXMulvdN37h88dvlvRyu61GYZau40fL4wEZvPEHvrjpJc3lDv6xDM5n4Z0StufUVB5nDvVZUM+jZHdMOOQ==", - "dev": true, - "requires": { - "array-from": "^2.1.1" - } + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.3.tgz", + "integrity": "sha512-8zNeBkSKhU9a5cRNbpCKau2WWPfan+Q2zDlcXvXyhn9EsMqgYs4qzo0XHNVlXC6ABQL8fT6nV+zzo5RTHJzyXw==", + "dev": true + }, + "@sinonjs/text-encoding": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", + "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", + "dev": true }, "ajv": { "version": "6.12.6", @@ -89,14 +95,14 @@ "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" }, "aws4": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz", - "integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==" + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", + "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "bcrypt-pbkdf": { @@ -158,7 +164,7 @@ }, "commander": { "version": "2.15.1", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", "dev": true }, @@ -356,15 +362,15 @@ } }, "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "is-object": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz", - "integrity": "sha1-iVJojF7C/9awPsyF52ngKQMINHA=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.2.tgz", + "integrity": "sha512-2rRIahhZr2UWb45fIOuvZGpFtz0TyOZLf32KxBbSoUCeZR495zCKlWUKKUByk3geS2eAs7ZAABt0Y/Rx0GiQGA==", "dev": true }, "is-typedarray": { @@ -415,9 +421,9 @@ } }, "just-extend": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-3.0.0.tgz", - "integrity": "sha512-Fu3T6pKBuxjWT/p4DkqGHFRsysc8OauWr4ZRTY9dIx07Y9O0RkoR5jcv28aeD1vuAwhm3nLkDurwLXoALp4DpQ==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", "dev": true }, "lodash": { @@ -444,16 +450,16 @@ "dev": true }, "mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", + "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==" }, "mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "version": "2.1.32", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz", + "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==", "requires": { - "mime-db": "1.44.0" + "mime-db": "1.49.0" } }, "minimatch": { @@ -528,16 +534,27 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "nise": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.5.tgz", - "integrity": "sha512-OHRVvdxKgwZELf2DTgsJEIA4MOq8XWvpSUzoOXyxJ2mY0mMENWC66+70AShLR2z05B1dzrzWlUQJmJERlOUpZw==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.3.tgz", + "integrity": "sha512-Ymbac/94xeIrMf59REBPOv0thr+CJVFMhrlAkW/gjCIE58BGQdCj0x7KRCb3yz+Ga2Rz3E9XXSvUyyxqqhjQAQ==", "dev": true, "requires": { - "@sinonjs/formatio": "3.0.0", - "just-extend": "^3.0.0", - "lolex": "^2.3.2", - "path-to-regexp": "^1.7.0", - "text-encoding": "^0.6.4" + "@sinonjs/formatio": "^3.2.1", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "lolex": "^5.0.1", + "path-to-regexp": "^1.7.0" + }, + "dependencies": { + "lolex": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-5.1.2.tgz", + "integrity": "sha512-h4hmjAvHTmd+25JSwrtTIuwbKdwg5NzZVRMLn9saij4SZaepCrTCxPr35H/3bjwfMJtN+t3CX8672UIkglz28A==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.7.0" + } + } } }, "oauth-sign": { @@ -561,24 +578,24 @@ "dev": true }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "path-to-regexp": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", - "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", "dev": true, "requires": { "isarray": "0.0.1" } }, "pathval": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", "dev": true }, "performance-now": { @@ -711,12 +728,6 @@ "has-flag": "^3.0.0" } }, - "text-encoding": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", - "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=", - "dev": true - }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -746,9 +757,9 @@ "dev": true }, "uri-js": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz", - "integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "requires": { "punycode": "^2.1.0" } diff --git a/package.json b/package.json index c96d83e..65dd245 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@parse/node-gcm", "description": "Easy interface for Google's Cloud Messaging service (now Firebase Cloud Messaging)", - "version": "1.0.2", + "version": "1.0.4", "author": "Marcus Farkas ", "contributors": [ "Marcus Farkas ", @@ -69,8 +69,8 @@ "test": "mocha test/**/*Spec.js" }, "dependencies": { - "debug": "^4.3.2", - "lodash": "^4.17.21", + "debug": "4.3.2", + "lodash": "4.17.21", "request": "2.88.2" }, "devDependencies": { diff --git a/test/unit/senderSpec.js b/test/unit/senderSpec.js index cecc54d..cef35ef 100644 --- a/test/unit/senderSpec.js +++ b/test/unit/senderSpec.js @@ -73,13 +73,12 @@ describe('UNIT Sender', function () { }, 10); }); - it('should not override internal request params if passed into constructor (except timeout)', function (done) { + it('should not override internal request params if passed into constructor (except timeout/uri)', function (done) { var options = { method: 'GET', headers: { Authorization: 'test' }, - uri: 'http://example.com', json: { test: true } }; var sender = new Sender('mykey', options); @@ -88,7 +87,6 @@ describe('UNIT Sender', function () { setTimeout(function() { expect(args.options.method).to.not.equal(options.method); expect(args.options.headers).to.not.deep.equal(options.headers); - expect(args.options.uri).to.not.equal(options.uri); expect(args.options.json).to.not.equal(options.json); done(); }, 10); @@ -124,6 +122,29 @@ describe('UNIT Sender', function () { }, 10); }); + it('should allow override for "uri" if passed into constructor via options', function (done) { + var options = { + uri: 'http://example.com' + }; + var sender = new Sender('mykey', options); + var m = new Message({ data: {} }); + sender.sendNoRetry(m, '', function () {}); + setTimeout(function() { + expect(args.options.uri).to.be.equal(options.uri); + done(); + }, 10); + }); + + it('should default "uri" to FCM send uri if not overridden', function (done) { + var sender = new Sender('mykey'); + var m = new Message({ data: {} }); + sender.sendNoRetry(m, '', function () {}); + setTimeout(function() { + expect(args.options.uri).to.be.equal(Constants.GCM_SEND_URI); + done(); + }, 10); + }); + it('should not set strictSSL of req object if not passed into constructor', function (done) { var options = { proxy: 'http://myproxy.com',