
/**
 * WPCONN module
 */

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

/**
 * Package
 */

var pkg = require('../package.json');

/**
 * Testing data
 */

var wpapp = require('./data');

/**
 * WPCONN instance
 */

var wpconn = new WPCONN();

/**
 * Sync tests
 */

describe('version', function(){
  it('should have x.x.x format', function(){
    pkg.version.should.match(/\d\.\d\.\d/);
  });
});

describe('wp app', function(){
  it('`client id` should be a string of numbers', function(){
    (Number(wpapp.client_id)).should.be.a.Number;
  });

  it('`client secret` lenght and type', function(){
    wpapp.client_secret
      .should.be.an.instanceOf(String)
      .and.length(64);
  });

  it('`token` should be an String', function(){
    wpapp.token
      .should.be.an.instanceOf(String);
  });
});

/**
 * WPCONN object
 */

describe('WPCONN object', function(){
  it('should create a WPCONN object', function(){
    var wpconn = new WPCONN();
    wpconn.should.be.instanceof(WPCONN);
  });

  it('should set the token', function(){
    var wpconn = new WPCONN();
    var token = wpapp.token;
    wpconn.setToken(token);

    wpconn.token
      .should.be.ok
      .and.be.instanceOf(String)
      .eql(token);
  });
});

/**
 * ME
 */

describe('me', function(){
  it('should require user object', function(done){
    var wpconn = getInstance();

    wpconn.me(function(err, me){
      if (err) throw err;

      // testing object
      me.should.be.ok
      .and.an.instanceOf(Object);

      // testing user data
      me.ID
        .should.be.an.instanceOf(Number);

      done();
    });
  });
});

/**
 * POSTS LIST
 */

describe('posts list', function(){
  it('should request posts list', function(done){
    var wpconn = getInstance();

    wpconn.me(function(err, me){
      if (err) throw err;

      // testing user token site id
      var token_site = me.token_site_id;

      // me object data testing
      token_site.should.be.an.instanceOf(Number);

      wpconn.posts(token_site, function(err, list){
        if (err) throw err;

        // list object data testing
        list.should.be.an.instanceOf(Object);

        done();
      });
    });
  });
});

/**
 * Testing useful function
 */

/**
 * Return a WPCONN instance
 */

function getInstance(){
  var wpconn = new WPCONN();
  var token = wpapp.token;
  wpconn.setToken(token);

  return wpconn;
}

@@ -2114,24 +2114,195 @@
 f(Object);%0A%0A
+        // %60posts list%60 object data testing%0A        list.found%0A          .should.be.an.instanceOf(Number);%0A%0A        list.posts%0A          .should.be.an.instanceOf(Array);%0A%0A
         done

improve `posts list` test