aboutsummaryrefslogtreecommitdiff
path: root/tests/active911.js
blob: 309aafb635ae165a5ad7fc390fdc36956a0c95b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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);
            });
        });
    });

});