/**
 * test/index.js
 * Contains tests for client entry point.
 *
 * @author Francis Brito <fr.br94@gmail.com>
 * @license MIT
 */
/* global describe, it, before */
/* jshint expr:true */
'use strict';

require('should');

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

var PH_TEST_SERVER = 'http://private-50d6dc-printhouse.apiary-mock.com/api';

describe('Client', function () {
    describe('constructor', function () {
        it('should throw if no API key is provided.', function () {
            (function () {
               new Client();
            }).should.throw('No API key provided.');
        });

        it('should use default API endpoint if none is provided.', function () {
            var client = new Client('some api key');

            // NOTE: Accessing client's private API, so sort of breaking the rules here.
            client._endpoint.should.eql(Client.DEFAULT_API_URL);
        });

        it('should use latest API version if none is specified.', function () {
            var client = new Client('some api key');

            client._version.should.eql(Client.DEFAULT_API_VERSION);
        });
    });

    describe('#getProducts', function () {
        before(function () {
            this.client = new Client('some api token', {
                endpoint: PH_TEST_SERVER
            });
        });

        it('should return a list of products.', function (next) {
            this.client.getProducts(function (err, products) {
                products.should.be.ok.and.be.an.Array;

                next();
            });
        });

        it('should throw if API endpoint is not reachable.');

        it('should throw if API endpoint responds with a server error.');
    });

    describe('#getProductById', function () {
        before(function () {
            this.client = new Client('some api token', {
                endpoint: PH_TEST_SERVER
            });
        });

        it('should throw if no product with id `id` is found.');

        it('should throw if no `id` field is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#getPrintFiles', function () {
        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#getPrintFileById', function () {
        it('should throw if no print file with id `id` is found.');
        it('should throw if no `id` field is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#createPrintFile', function () {
        it('should throw if no `fields` parameter is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#getOrders', function () {
        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#getOrderById', function () {
        it('should throw if no order with id `id` is found.');
        it('should throw if no `id` field is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#createOrder', function () {
        it('should throw if no `fields` parameter is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#updateOrder', function () {
        it('should throw if no order with id `id` is found.');
        it('should throw if no `id` field is provided.');
        it('should throw if order has already being confirmed.');
        it('should throw if no `fields` parameter is provided.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });

    describe('#confirmOrder', function () {
        it('should throw if no order with id `id` is found.');
        it('should throw if no `id` field is provided.');
        it('should throw if order was already confirmed.');

        it('should throw if API endpoint is not reachable.');
        it('should throw if API endpoint responds with a server error.');
    });
});

/*
 * Helpers
 */
// function isACanvas(c) { return c.kind === 'Canvas'; }
// function every(array, predicate) { return array.every(predicate); }

@@ -253,16 +253,41 @@
 lient;%0A%0A
+var they = it.bind(it);%0A%0A
 var PH_T
@@ -1138,32 +1138,219 @@
    %7D);%0A    %7D);%0A%0A
+    describe('methods', function () %7B%0A        they('should throw if API endpoint is not reachable.');%0A        they('should throw if API endpoint responds with a server error.');%0A    %7D);%0A%0A
     describe('#g
@@ -1772,146 +1772,8 @@
  %7D);
-%0A%0A        it('should throw if API endpoint is not reachable.');%0A%0A        it('should throw if API endpoint responds with a server error.');
 %0A   
@@ -2041,25 +2041,24 @@
 s found.');%0A
-%0A
         it('
@@ -2107,339 +2107,61 @@
 ');%0A
-%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');%0A    %7D);%0A%0A    describe('#getPrintFiles', function () %7B%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');%0A    
+    %7D);%0A%0A    describe('#getPrintFiles', function () %7B
 %7D);%0A
@@ -2338,145 +2338,8 @@
 .');
-%0A%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');
 %0A   
@@ -2452,34 +2452,32 @@
 provided.');
-%0A%0A
         
 it('should t
@@ -2468,883 +2468,341 @@
     
-it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');%0A    %7D);%0A%0A    describe('#getOrders', function () %7B%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');%0A    %7D);%0A%0A    describe('#getOrderById', function () %7B%0A        it('should throw if no order with id %60id%60 is found.');%0A        it('should throw if no %60id%60 field is provided.');%0A%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');%0A    %7D);%0A%0A    describe('#createOrder', function () %7B%0A        it('should throw if no %60fields%60 parameter is provided.');%0A%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error
+%0A    %7D);%0A%0A    describe('#getOrders', function () %7B%7D);%0A%0A    describe('#getOrderById', function () %7B%0A        it('should throw if no order with id %60id%60 is found.');%0A        it('should throw if no %60id%60 field is provided.');%0A    %7D);%0A%0A    describe('#createOrder', function () %7B%0A        it('should throw if no %60fields%60 parameter is provided
 .');
@@ -3110,145 +3110,8 @@
 .');
-%0A%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');
 %0A   
@@ -3344,145 +3344,8 @@
 .');
-%0A%0A        it('should throw if API endpoint is not reachable.');%0A        it('should throw if API endpoint responds with a server error.');
 %0A   

Move API reachable and response error tests.