/**
 * hybridify <https://github.com/tunnckoCore/hybridify>
 *
 * Copyright (c) 2015 Charlike Mike Reagent, contributors.
 * Released under the MIT license.
 */

'use strict';

var hybridify = require('./index');

var handleCallback = require('./index');
var assert = require('assert');
var got = require('got');

var hybridGot = hybridify(got.get);

// almost the same tests as `handle-callback`,
// which is expected, because its the core of `hybridify`

describe('hybridify:', function() {
  describe('should work', function() {
    it('with callback api', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://github.com', function(err, res) {
        var body = res[0];
        var stream = res[1];

        // callback api

        assert.strictEqual(err, null);
        assert(res);
        assert(stream);
        assert.strictEqual(body[0], '<'); // it is html
        done()
      })
    });

    it('with promise api', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://github.com');
      hybrid.then(function(res) {
        var body = res[0];
        var stream = res[1];

        // promise api

        assert(res);
        assert(stream);
        assert.strictEqual(body[0], '<'); // it is html
        done()
      });
    });

    it('with both callback and promise api', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://github.com', function(err, res) {
        var body = res[0];
        var stream = res[1];

        // callback api

        assert.strictEqual(err, null);
        assert(res);
        assert(stream);
        assert.strictEqual(body[0], '<'); // it is html
      })
      .then(function(res) {
        var body = res[0];
        var stream = res[1];

        // promise api

        assert(res);
        assert(stream);
        assert.strictEqual(body[0], '<'); // it is html
        done()
      });
    });
  });


  describe('should be able to catch error', function() {
    it('with callback api', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://gitfsdfsdfm', function(err, res) {

        assert.throws(err, Error);

        // callback api

        assert.strictEqual(res, null || undefined);
        done();
      })
    });

    it('with promise api - with .catch(err)', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://gitfsdfsdfm')
      hybrid.catch(function(err) {
        // promise api
        assert.throws(err, Error);
        done();
      })
    });

    it('with both callback and promise api', function(done) {
      this.timeout(10000);

      var hybrid = hybridGot('https://gitfsdfsdfm', function(err) {
        // callback api
        assert.throws(err, Error);
      })
      .catch(function(err) {
        // promise api
        assert.throws(err, Error);
        done();
      })
    });
  });

  describe('should throw error', function() {
    it('when first argument not a Function', function(done) {
      function iifn() {
        return hybridify('expects only function');
      }
      assert.throws(iifn, TypeError);
      done()
    });
  });
});

@@ -486,16 +486,280 @@
 ion() %7B%0A
+  describe('should throw error', function() %7B%0A    it('when first argument not a Function', function(done) %7B%0A      function fixture() %7B%0A        return hybridify('expects only function');%0A      %7D%0A      assert.throws(fixture, TypeError);%0A      done();%0A    %7D);%0A  %7D);%0A%0A
   descri
@@ -781,32 +781,32 @@
 ', function() %7B%0A
-
     it('with cal
@@ -982,33 +982,32 @@
 tream = res%5B1%5D;%0A
-%0A
         // callb
@@ -1161,32 +1161,33 @@
 l%0A        done()
+;
 %0A      %7D)%0A    %7D)
@@ -1395,33 +1395,32 @@
 tream = res%5B1%5D;%0A
-%0A
         // promi
@@ -1534,32 +1534,33 @@
 l%0A        done()
+;
 %0A      %7D);%0A    %7D
@@ -1773,33 +1773,32 @@
 tream = res%5B1%5D;%0A
-%0A
         // callb
@@ -2039,17 +2039,16 @@
 res%5B1%5D;%0A
-%0A
         
@@ -2174,24 +2174,25 @@
       done()
+;
 %0A      %7D);%0A 
@@ -2205,16 +2205,765 @@
 %0A  %7D);%0A%0A
+  describe('should be able to create own hybrids', function() %7B%0A    it('every hybrid have %60.hybridify%60 method', function(done) %7B%0A      var hybrid = hybridGot('https://github.com');%0A%0A      assert.strictEqual(typeof hybrid.hybridify, 'function');%0A      assert.strictEqual(typeof hybridGot.hybridify, 'function');%0A      done();%0A    %7D);%0A    it('every hybrid is promise and have %60.then%60 and %60.catch%60 methods', function(done) %7B%0A      var hybrid = hybridGot('https://github.com');%0A%0A      assert.strictEqual(typeof hybrid.then, 'function');%0A      assert.strictEqual(typeof hybrid.catch, 'function');%0A      assert.strictEqual(typeof hybrid.hybridify, 'function');%0A      assert.strictEqual(typeof hybridGot.hybridify, 'function');%0A      done();%0A    %7D);%0A  %7D);%0A
 %0A  descr
@@ -3158,17 +3158,40 @@
  res) %7B%0A
+        // callback api
 %0A
-
         
@@ -3221,34 +3221,8 @@
 r);%0A
-%0A        // callback api%0A%0A
     
@@ -3894,32 +3894,32 @@
         done();%0A
+
       %7D)%0A    %7D);
@@ -3928,265 +3928,8 @@
  %7D);
-%0A%0A  describe('should throw error', function() %7B%0A    it('when first argument not a Function', function(done) %7B%0A      function iifn() %7B%0A        return hybridify('expects only function');%0A      %7D%0A      assert.throws(iifn, TypeError);%0A      done()%0A    %7D);%0A  %7D);
 %0A%7D);

add new tests, lint