/**
 * @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);
  });

  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.only('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);
  });

});


@@ -799,16 +799,57 @@
 %0A  %7D);%0A%0A
+  describe('Create Ops', function () %7B%0A  
   it('Wi
@@ -891,32 +891,34 @@
 ion(done) %7B%0A    
+  
 req.post('/appli
@@ -924,32 +924,34 @@
 ication')%0A      
+ 
+ 
 .send(%7Bname: 'on
@@ -982,32 +982,34 @@
 .three'%7D)%0A      
+  
 .expect('locatio
@@ -1034,32 +1034,34 @@
 -to%5C-go/)%0A      
+ 
+ 
 .expect(302, don
@@ -1068,16 +1068,18 @@
 e);%0A
+  
   %7D);%0A  
 it.o
@@ -1078,15 +1078,12 @@
 ;%0A  
+  
 it
-.only
 ('Wi
@@ -1156,24 +1156,26 @@
 done) %7B%0A    
+  
 req.post('/a
@@ -1183,24 +1183,26 @@
 plication')%0A
+  
       .set('
@@ -1232,24 +1232,26 @@
 son')%0A      
+ 
+ 
 .send(%7Bname:
@@ -1286,32 +1286,34 @@
 .three'%7D)%0A      
+  
 .expect('Content
@@ -1326,32 +1326,34 @@
 , /json/)%0A      
+ 
+ 
 .expect(200)%0A   
@@ -1349,16 +1349,18 @@
 ct(200)%0A
+  
       .e
@@ -1389,16 +1389,18 @@
         
+ 
+ 
 expect(r
@@ -1433,16 +1433,18 @@
         
+  
 'name',%0A
@@ -1453,16 +1453,18 @@
         
+ 
+ 
 'uniqueU
@@ -1478,16 +1478,18 @@
         
+  
 'hostnam
@@ -1502,16 +1502,18 @@
         
+ 
+ 
 'ownerId
@@ -1515,16 +1515,18 @@
 nerId',%0A
+  
         
@@ -1550,16 +1550,18 @@
         
+ 
+ 
 'tokens'
@@ -1570,16 +1570,18 @@
         
+  
 %5D);%0A    
@@ -1582,16 +1582,18 @@
 ;%0A      
+ 
+ 
 %7D).end(d
@@ -1602,16 +1602,923 @@
 e);%0A
+  
   %7D);%0A
+  %7D);%0A  describe('Read 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 read a record', function(done) %7B%0A      req.get('/application/' + appDoc.uniqueUrl)%0A        .expect(200)%0A        .expect(/one%5C-to%5C-go/, done);%0A    %7D);%0A    it.only('Will read a record using JSON', function(done) %7B%0A      req.get('/application/' + appDoc.uniqueUrl)%0A        .set('Accept', 'application/json')%0A        .expect('Content-Type', /json/)%0A        .expect(200)%0A        .expect(function(res) %7B%0A          expect(res.body).to.have.keys(%5B%0A            'name',%0A            'uniqueUrl',%0A            'hostname',%0A            'ownerId',%0A            'createdOn',%0A            'tokens',%0A          %5D);%0A        %7D).end(done);%0A    %7D);%0A  %7D);
 %0A%7D);
-%0A
 %0A

create app read tests