Skip to content

Commit cb974e7

Browse files
authored
[RADAR-689] Prevents null error when options is null (#12)
* Prevents null error when options is null In an upstream repo we sometimes pass null to the options when building a presence sync, which was throwing an error. Adding some tests for that scenario, and the fix * updates version to v1.3.1
1 parent 7c1992f commit cb974e7

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v1.3.1
2+
* [PR #12](https://github.com/zendesk/radar_message/pull/12) - Fixes an error when `options: null` is passed to presence sync
3+
14
### v1.3.0
25
* [PR #10](https://github.com/zendesk/radar_message/pull/10) - Updates packages and runs Travis in Node 10 & 12
36
* [PR #11](https://github.com/zendesk/radar_message/pull/11) - Updates packages, adds standard and fixes offences, adds a PR template and updates to ES6 syntax

lib/message_request.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Request.buildUnsubscribe = function (scope, message = { op: 'unsubscribe', to: s
7272
// Instance methods
7373

7474
Request.prototype.forceV2Sync = function (options = {}) {
75+
options = options || {} // options is sometimes null, which would cause an exception on the next line
7576
options.version = 2
7677
this.setAttr('options', options)
7778
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "radar_message",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "radar message api library",
55
"main": "lib/index.js",
66
"author": "Zendesk, Inc.",

test/request.unit.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ describe('Request', function () {
7979
assert.strictEqual(request.getType(), 'message')
8080
})
8181

82+
it('build a presence request', function () {
83+
const request = Request.buildSync('presence:/test/ticket/1')
84+
85+
assert.deepStrictEqual(
86+
request.getMessage(),
87+
{
88+
op: 'sync',
89+
to: 'presence:/test/ticket/1',
90+
options: {
91+
version: 2
92+
}
93+
})
94+
assert.strictEqual(request.getType(), 'presence')
95+
})
96+
97+
it('build a presence request, with options null', function () {
98+
const request = Request.buildSync('presence:/test/ticket/1', null)
99+
100+
assert.deepStrictEqual(
101+
request.getMessage(),
102+
{
103+
op: 'sync',
104+
to: 'presence:/test/ticket/1',
105+
options: {
106+
version: 2
107+
}
108+
})
109+
assert.strictEqual(request.getType(), 'presence')
110+
})
111+
82112
it('build a subscribe request', function () {
83113
const request = Request.buildSubscribe('presence:/test/ticket/1')
84114

0 commit comments

Comments
 (0)