Built motion from commit 17d0c2b.|2.0.3
[motion2.git] / server / test / voiceContext.js
1 'use strict';
2
3 var mysqldb = require('../mysqldb');
4 var config = require('../config/environment');
5
6 var util = require('util');
7 var chai = require('chai');
8 var chaiHttp = require('chai-http');
9 var should = chai.should();
10
11 chai.use(chaiHttp);
12
13 describe('Voice Contexts', function() {
14     /*
15      * Test the /POST voice/contexts
16      */
17     describe('/POST voice/contexts', function() {
18         it('it should POST one contexts without errors', function(done) {
19             chai
20                 .request(util.format('http://%s:%s/api', config.ip, config.port))
21                 .post('/voice/contexts')
22                 .send({
23                     name: 'Name',
24                     prefix: 'Prefix'
25                 })
26                 .then(function(res) {
27                     res.should.have.status(201);
28
29                     done();
30                 });
31         });
32     });
33
34
35     /*
36      * Test the /GET voice/contexts
37      */
38     describe('/GET voice/contexts', function() {
39         it('it should GET one voice/contexts without errors', function(done) {
40             chai
41                 .request(util.format('http://%s:%s/api', config.ip, config.port))
42                 .get('/voice/contexts')
43                 .then(function(res) {
44                     res.body.count.should.equal(1);
45                     res.should.have.status(200);
46
47                     done();
48                 });
49         });
50     });
51
52     /*
53      * Test the /GET voice/contexts/{id}
54      */
55     describe('/GET voice/contexts/1', function() {
56         it('it should GET one contexts with id=1 without errors', function(done) {
57             chai
58                 .request(util.format('http://%s:%s/api', config.ip, config.port))
59                 .get('/voice/contexts/1')
60                 .then(function(res) {
61                     res.body.id.should.equal(1);
62                     res.should.have.status(200);
63
64                     done();
65                 });
66         });
67     });
68
69     /*
70      * Test the /PUT voice/contexts/{id}
71      */
72     describe('/PUT voice/contexts/1', function() {
73         it('it should PUT one contexts with id=1 without errors', function(done) {
74             chai
75                 .request(util.format('http://%s:%s/api', config.ip, config.port))
76                 .put('/voice/contexts/1')
77                 .send({
78                     name: 'Name II'
79                 })
80                 .then(function(res) {
81                     res.body.name.should.equal('Name II');
82                     res.should.have.status(200);
83
84                     done();
85                 });
86         });
87     });
88
89     /*
90      * Test the /DELETE voice/contexts/{id}
91      */
92     describe('/DELETE voice/contexts1', function() {
93         it('it should DELETE one contexts with id=1 without errors', function(done) {
94             chai
95                 .request(util.format('http://%s:%s/api', config.ip, config.port))
96                 .delete('/voice/contexts/1')
97                 .then(function(res) {
98                     res.should.have.status(204);
99
100                     done();
101                 });
102         });
103     });
104 });