
/**
 * Module dependecies
 */

var util = require('./util');
var Site = require('../lib/site');
var assert = require('assert');

/**
 * Testing data
 */

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

/**
 * WPCOM object
 */

describe('wpcom', function(){
  // Global instances
  var wpcom = util.wpcom();
  var site = wpcom.site(util.site());
  var testing_post;

  describe('wpcom.util.req.post', function(){

    describe('create a post without query {} and body {}', function(){
      it('should get 400 error code', function(done){

        var path = '/sites/' + site._id + '/posts/new';
        wpcom.req.post(path, function(err, data){
          assert.ok(err);
          assert.equal(400, err.statusCode);
          done();
        });

      });
    });

    describe('create a post without query {}', function(){
      it('should create a new post', function(done){

        var path = '/sites/' + site._id + '/posts/new';
        wpcom.req.post(path, null, fixture.post, function(err, data){
          if (err) throw err;

          testing_post = data;
          assert.ok(data);
          done();
        });

      });
    });

  });

  describe('wpcom.util.req.del', function(){
    it('should delete added post', function(done){
      var path = '/sites/' + site._id + '/posts/' + testing_post.ID + '/delete';
      wpcom.req.post(path,  function(err, data){
        if (err) throw err;

        assert.ok(data.ID, testing_post.ID);
        done();
      });

    });
  });

});


/**
 * Module dependecies
 */

var util = require('./util');
var Site = require('../lib/site');
var assert = require('assert');

/**
 * Testing data
 */

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

/**
 * WPCOM object
 */

describe('wpcom', function(){
  // Global instances
  var wpcom = util.wpcom();
  var site = wpcom.site(util.site());
  var testing_post;

  describe('wpcom.util.req.post', function(){

    describe('create a post without query {} and body {}', function(){
      it('should get 400 error code', function(done){

        var path = '/sites/' + site._id + '/posts/new';
        wpcom.req.post(path)
          .then(() => done('No error returned'))
          .catch(err=>{
            assert.ok(err);
            assert.equal(400, err.statusCode);
            done();
          });
      });
    });

    describe('create a post without query {}', function(){
      it('should create a new post', function(done){

        var path = '/sites/' + site._id + '/posts/new';
        wpcom.req.post(path, null, fixture.post)
          .then( data => {
            testing_post = data;
            assert.ok(data);
            done();
          })
          .catch(done);
      });
    });

  });

  describe('wpcom.util.req.del', function(){
    it('should delete added post', function(done){
      var path = '/sites/' + site._id + '/posts/' + testing_post.ID + '/delete';
      wpcom.req.post(path)
        .then(data => {
          assert.ok(data.ID, testing_post.ID);
          done();
        })
        .catch(done);
    });
  });

});

Cover tests: util.req