aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Burwell <bburwell1@gmail.com>2014-10-22 08:35:44 -0400
committerBen Burwell <bburwell1@gmail.com>2014-10-22 08:35:44 -0400
commit05337261ffb4abfb0fbbb9c775ccad0e28645692 (patch)
tree973f24e72570cc4d721957e70adf51387c13598b /tests
parentc2d82325318085b89d255e84384651db680c0c97 (diff)
Begin rewrite for new API
Diffstat (limited to 'tests')
-rw-r--r--tests/active911.js105
-rw-r--r--tests/replies/agency.json24
-rw-r--r--tests/replies/device.json19
-rw-r--r--tests/replies/devices.json0
-rw-r--r--tests/replies/error.json4
5 files changed, 152 insertions, 0 deletions
diff --git a/tests/active911.js b/tests/active911.js
new file mode 100644
index 0000000..309aafb
--- /dev/null
+++ b/tests/active911.js
@@ -0,0 +1,105 @@
+require('should');
+require('nock');
+Active911 = require('../lib/active911.js');
+
+var a911;
+
+var testDevicesResponse = require('replies/devices.json');
+var testAgencyResponse = require('replies/agency.json');
+var testDeviceResponse = require('replies/device.json');
+var testErrorResponse = require('replies/error.json');
+
+describe('Active911 API', function() {
+
+ beforeEach(function(done) {
+ a911 = new Active911();
+ });
+
+ describe('#getAgency', function() {
+
+ it('Should return correct agency data', function() {
+
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/')
+ .replyWithFile(200, __dirname + 'replies/agency.json'});
+
+ a911.getAgency(function(err, agency) {
+ should.not.exist(err);
+ agency.should.equal(testAgencyResponse.message.agency);
+ });
+ });
+
+ it('Should give an error if the API gives an error', function() {
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/')
+ .replyWithFile(400, __dirname + 'replies/error.json');
+
+ a911.getAgency(function(err, agency) {
+ err.should.equal(testErrorResponse.message);
+ should.not.exist(agency);
+ });
+ });
+
+ });
+
+ describe('#getDevices', function() {
+ it('Should return correct device data', function() {
+
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/')
+ .replyWithFile(400, __dirname + 'replies/agency.json');
+
+ a911.getDevices(function(err, devices) {
+ should.not.exist(err);
+ devices.should.equal(testDevicesResponse.message.devices);
+ });
+ });
+
+ it('Should give an error if the API gives an error', function() {
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/')
+ .replyWithFile(400, __dirname + 'replies/error.json');
+
+ a911.getDevices(function(err, devices) {
+ err.should.equal(testErrorResponse.message);
+ should.not.exist(devices);
+ });
+ });
+ });
+
+ describe('#getDevice', function() {
+ it('Should return correct device data (String id)', function() {
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/devices/1')
+ .replyWithFile(200, __dirname + 'replies/device.json');
+
+ a911.getDevice('1', function(err, device) {
+ should.not.exist(err);
+ device.should.equal(testDeviceResponse.message.device);
+ });
+ });
+
+ it('Should return correct device data (Number id)', function() {
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/devices/1')
+ .replyWithFile(200, __dirname + 'replies/device.json');
+
+ a911.getDevice(1, function(err, device) {
+ should.not.exist(err);
+ device.should.equal(testDeviceResponse.message.device);
+ });
+ });
+
+ it('Should give an error if the API gives an error', function() {
+ nock('https://access.active911.com')
+ .get('/interface/open_api/api/devices/1')
+ .replyWithFile(400, __dirname + 'replies/error.json');
+
+ a911.getDevice(1, function(err, device) {
+ err.should.equal(testErrorResponse.message);
+ should.not.exist(device);
+ });
+ });
+ });
+
+});
diff --git a/tests/replies/agency.json b/tests/replies/agency.json
new file mode 100644
index 0000000..6c1b365
--- /dev/null
+++ b/tests/replies/agency.json
@@ -0,0 +1,24 @@
+{
+ "result": "success",
+ "message": {
+ "agency": {
+ "id": "12345",
+ "name": "Test Agency",
+ "address": "123 Main St.",
+ "city": "City",
+ "state": "AZ",
+ "latitude": 40,
+ "longitude": 70,
+ "devices": [
+ {
+ "id": 1,
+ "uri": "https://access.active911.com/interface/open_api/api/devices/1"
+ },
+ {
+ "id": 2,
+ "uri": "https://access.active911.com/interface/open_api/api/devices/2"
+ }
+ ]
+ }
+ }
+}
diff --git a/tests/replies/device.json b/tests/replies/device.json
new file mode 100644
index 0000000..b3dc1ee
--- /dev/null
+++ b/tests/replies/device.json
@@ -0,0 +1,19 @@
+{
+ "result": "success",
+ "message": {
+ "device": {
+ "id": 1,
+ "name": "Test Device",
+ "latitude": 41,
+ "longitude": 71,
+ "position_accuracy": "100",
+ "position_timestamp": "2014-01-01 00:00:00",
+ "agencies": [
+ {
+ "id": "12345",
+ "uri": "https://access.active911.com/interface/open_api/api/"
+ }
+ ]
+ }
+ }
+}
diff --git a/tests/replies/devices.json b/tests/replies/devices.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/replies/devices.json
diff --git a/tests/replies/error.json b/tests/replies/error.json
new file mode 100644
index 0000000..c9ccbef
--- /dev/null
+++ b/tests/replies/error.json
@@ -0,0 +1,4 @@
+{
+ "result": "error",
+ "message": "Test Error Message"
+}