/**
 * @fileOverview Application CRUD tests.
 */

var chai = require('chai');
var expect = chai.expect;

var kansasApi = require('../../');

var tester = require('../lib/tester');
var Web = require('../lib/web');

describe('Application CRUD ops', function() {
  var req;
  var expressApp;
  var kansas;

  before(function(done) {
    kansas = kansasApi();
    kansas.connect().then(function() {
      tester.express(6699, function(app) {
        expressApp = app;
        kansas.express(expressApp);
      }).then(done.bind(null, null));
    }).catch(done);
  });

  beforeEach(function(done) {
    var web = new Web(expressApp);
    req = web.req;
    done();
  });

  beforeEach(function(done) {
    kansas.appEnt.delete({name: 'one-to-go'})
      .then(done.bind(null, null))
      .catch(done);
  });

  describe('Create Ops', function () {
    it('Will create a new application', function(done) {
      req.post('/application')
        .send({name: 'one-to-go', hostname: 'two.three'})
        .expect('location', /[\d]{6}\-one\-to\-go/)
        .expect(302, done);
    });
    it('Will create a new application and return the JSON object', function(done) {
      req.post('/application')
        .set('Accept', 'application/json')
        .send({name: 'one-to-go', hostname: 'two.three'})
        .expect('Content-Type', /json/)
        .expect(200)
        .expect(function(res) {
          expect(res.body).to.have.keys([
            'name',
            'uniqueUrl',
            'hostname',
            'ownerId',
            'createdOn',
            'tokens',
          ]);
        }).end(done);
    });
  });
  describe('Read Ops', function() {
    var appDoc;
    beforeEach(function(done) {
      kansas.appEnt.create({
        name: 'one-to-go',
        hostname: 'two.three',
      }).then(function(doc) {
        appDoc = doc;
      }).then(done, done);
    });

    it('Will read a record', function(done) {
      req.get('/application/' + appDoc.uniqueUrl)
        .expect(200)
        .expect(/one\-to\-go/, done);
    });
    it('Will read a record using JSON', function(done) {
      req.get('/application/' + appDoc.uniqueUrl)
        .set('Accept', 'application/json')
        .expect('Content-Type', /json/)
        .expect(200)
        .expect(function(res) {
          expect(res.body).to.have.keys([
            'name',
            'uniqueUrl',
            'hostname',
            'ownerId',
            'createdOn',
            'tokens',
          ]);
        }).end(done);
    });
  });
});

@@ -2508,12 +2508,646 @@
 ;%0A  %7D);%0A
+  describe('Delete Ops', function() %7B%0A    var appDoc;%0A    beforeEach(function(done) %7B%0A      kansas.appEnt.create(%7B%0A        name: 'one-to-go',%0A        hostname: 'two.three',%0A      %7D).then(function(doc) %7B%0A        appDoc = doc;%0A      %7D).then(done, done);%0A    %7D);%0A%0A    it('Will delete a record', function(done) %7B%0A      req.del('/application/' + appDoc.uniqueUrl)%0A        .expect(200)%0A        .end(function(err) %7B%0A          if (err) %7B return done(err); %7D%0A          kansas.appEnt.readOne(%7Bname: 'one-to-go'%7D)%0A            .then(function(res) %7B%0A              expect(res).to.be.null;%0A            %7D).then(done, done);%0A        %7D);%0A    %7D);%0A  %7D);%0A
 %7D);%0A

create delete test case