pushwoosh-client
Advanced tools
Comparing version 1.2.1 to 1.3.0
22
index.js
@@ -151,2 +151,24 @@ var request = require('request'), | ||
PushwooshClient.prototype.unregisterDevice = function (options, callback) { | ||
var client = this; | ||
if (typeof options.hwid !== 'string') { | ||
return callback(new Error('Device hwid must be provided (string)')); | ||
} | ||
var body = { | ||
request: { | ||
application: client.appCode, | ||
hwid: options.hwid | ||
} | ||
}; | ||
client.sendRequest('unregisterDevice', body, function(error, response, body){ | ||
if (error) { | ||
return callback(error); | ||
} | ||
client.parseResponse(response, body, callback); | ||
}); | ||
}; | ||
PushwooshClient.prototype.sendRequest = function (method, data, callback) { | ||
@@ -153,0 +175,0 @@ request({ |
{ | ||
"name": "pushwoosh-client", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "A node js client to consume the Pushwoosh API to send push notifications to mobile devices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -119,2 +119,18 @@ # pushwoosh-node-client | ||
#### Unregister device | ||
To unregister a device in Pushwoosh: | ||
```javascript | ||
var Pushwoosh = require('pushwoosh-client'); | ||
var client= new Pushwoosh('AppCode', 'AuthToken'); | ||
var unregisterDeviceOptions = { | ||
hwid: 'hwid' | ||
}; | ||
// this will unregister the device from the client's 'AppCode' application | ||
client.unregisterDevice(unregisterDeviceOptions, function(error, response) { | ||
... | ||
}); | ||
``` | ||
### Tests | ||
@@ -121,0 +137,0 @@ |
@@ -501,3 +501,3 @@ var test = require('tape'), | ||
test('Pushwoosh send message success case with response code 500', function (t) { | ||
test('Pushwoosh send message error case with response code 500', function (t) { | ||
t.plan(5); | ||
@@ -547,3 +547,3 @@ | ||
test('Pushwoosh send message success case with response code 500 test 2', function (t) { | ||
test('Pushwoosh send message error case with response code 500 test 2', function (t) { | ||
t.plan(5); | ||
@@ -588,3 +588,3 @@ | ||
test('Pushwoosh send message success case with response code 400', function (t) { | ||
test('Pushwoosh send message error case with response code 400', function (t) { | ||
t.plan(5); | ||
@@ -1033,3 +1033,3 @@ | ||
test('Pushwoosh register token success case with response code 400', function (t) { | ||
test('Pushwoosh register token error case with response code 400', function (t) { | ||
t.plan(5); | ||
@@ -1058,4 +1058,3 @@ | ||
} | ||
}, | ||
expectedResult = {description: 'Argument error', detail: mockBodyResponse.status_message, code: 210}; | ||
}; | ||
@@ -1078,3 +1077,3 @@ fraudster.registerMock('request', function (params, callback) { | ||
test('Pushwoosh register token success case with response code 400', function (t) { | ||
test('Pushwoosh register token error case with response code 500', function (t) { | ||
t.plan(5); | ||
@@ -1104,4 +1103,3 @@ | ||
} | ||
}, | ||
expectedResult = {description: 'Argument error', detail: mockBodyResponse.status_message, code: 210}; | ||
}; | ||
@@ -1123,1 +1121,167 @@ fraudster.registerMock('request', function (params, callback) { | ||
}); | ||
test('Pushwoosh unregister token success case', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 200, | ||
response: {} | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.unregisterDevice(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, {}, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh unregister token error case with no hwid', function (t) { | ||
t.plan(2); | ||
var mockOptions = {}; | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.unregisterDevice(mockOptions, function (err, response) { | ||
t.deepEqual(err, new Error('Device hwid must be provided'), 'Error as expected'); | ||
t.notOk(response, 'No response as expected'); | ||
}); | ||
}); | ||
test('Pushwoosh unregister token success case with response code 200 but status code 210', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 200 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 210, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}, | ||
expectedResult = {description: 'Argument error', detail: mockBodyResponse.status_message, code: 210}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.unregisterDevice(mockOptions, function (err, response) { | ||
t.notOk(err, 'No error as expected'); | ||
t.deepEqual(response, expectedResult, 'response is the same'); | ||
}); | ||
}); | ||
test('Pushwoosh unregister token error case with response code 400', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 400 | ||
}, | ||
mockBodyResponse = { | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.unregisterDevice(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Malformed(), 'Got Malformed Error!'); | ||
}); | ||
}); | ||
test('Pushwoosh unregister token error case with response code 500', function (t) { | ||
t.plan(5); | ||
var mockHwid = 'someHwid', | ||
mockOptions = { | ||
hwid: mockHwid | ||
}, | ||
mockResponse = { | ||
statusCode: 500 | ||
}, | ||
mockBodyResponse = { | ||
status_code: 500, | ||
response: {}, | ||
status_message: testError | ||
}, | ||
expectedBody = { | ||
request: { | ||
application: testAppCode, | ||
hwid: mockHwid | ||
} | ||
}; | ||
fraudster.registerMock('request', function (params, callback) { | ||
t.ok(params, 'Params exists'); | ||
t.deepEqual(params.body, expectedBody, 'Body are as expected'); | ||
t.equal(params.method, 'POST', 'Method is POST as expected'); | ||
callback(null, mockResponse, mockBodyResponse); | ||
}); | ||
var PwClient = getCleanTestObject(), | ||
client = new PwClient(testAppCode, testAuthToken); | ||
client.unregisterDevice(mockOptions, function (err, response) { | ||
t.notOk(response, 'No error as expected'); | ||
t.deepEqual(err, new errors.Internal(), 'Got Internal Error!'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52947
1251
140