var superagent = require('superagent');
var expect = require('expect.js');
var generateUUID = require('../lib/mongoose-uuid').generateUUID;

describe('express rest API for devices', function() {
    var id,
        UUID = generateUUID();

    it('post object', function(done) {
        superagent.post('http://localhost:3000/api/devices')
            .send({
                uuid: UUID,
                _type: 1
            })
            .end(function(e, res) {
                // console.log(res.body)
                // console.log('============')
                expect(e).to.eql(null);
                expect(typeof res.body).to.eql('object');
                expect(res.body._id);
                id = res.body._id;
                done();
            });
    });

    it('retrieves an object', function(done) {
        superagent.get('http://localhost:3000/api/devices/' + id)
            .end(function(e, res) {
                console.log(res.body)
                expect(e).to.eql(null);
                expect(typeof res.body).to.eql('object');
                expect(res.body._id);
                expect(res.body._id).to.eql(id);
                done();
            });
    });

    it('retrieves a collection', function(done) {
        superagent.get('http://localhost:3000/api/devices')
            .end(function(e, res) {
                // console.log(res.body)
                expect(e).to.eql(null);
                expect(res.body.length).to.be.above(0);
                expect(res.body.map(function(item) {
                    return item._id;
                })).to.contain(id);
                done();
            });
    });

    it('updates an object', function(done) {
        superagent.put('http://localhost:3000/api/devices/' + id)
            .send({
                _type: 1
            })
            .end(function(e, res) {
                // console.log(res.body)
                expect(e).to.eql(null);
                expect(typeof res.body).to.eql('object');
                done();
            });
    });

    it('checks an updated object', function(done) {
        superagent.get('http://localhost:3000/api/devices/' + id)
            .end(function(e, res) {
                // console.log(res.body)
                expect(e).to.eql(null);
                expect(typeof res.body).to.eql('object');
                expect(res.body._id.length);
                expect(res.body._id).to.eql(id);
                expect(res.body._type).to.eql(1);
                done();
            });
    });

    it('removes an object', function(done) {
        superagent.del('http://localhost:3000/api/devices/' + id)
            .end(function(e, res) {
                // console.log(res.body)
                expect(e).to.eql(null);
                expect(typeof res.body).to.eql('object');
                // expect(res.body.msg).to.eql('success');
                done();
            });
    });
});

@@ -196,18 +196,18 @@
     var 
-id
+ID
 ,%0A      
@@ -696,18 +696,18 @@
         
-id
+ID
  = res.b
@@ -865,34 +865,34 @@
 api/devices/' + 
-id
+ID
 )%0A            .e
@@ -928,16 +928,19 @@
         
+ //
  console
@@ -1126,34 +1126,34 @@
 ody._id).to.eql(
-id
+ID
 );%0A             
@@ -1592,18 +1592,18 @@
 contain(
-id
+ID
 );%0A     
@@ -1745,34 +1745,34 @@
 api/devices/' + 
-id
+ID
 )%0A            .s
@@ -2147,34 +2147,34 @@
 api/devices/' + 
-id
+ID
 )%0A            .e
@@ -2423,18 +2423,18 @@
 .to.eql(
-id
+ID
 );%0A     
@@ -2634,18 +2634,18 @@
 ces/' + 
-id
+ID
 )%0A      
@@ -2817,67 +2817,8 @@
 ');%0A
-                // expect(res.body.msg).to.eql('success');%0A
     

Clean up