var chai = require('chai');
var Treasury = require('../../index');

describe('Test supported promise factories', testPromiseFactories);

function testPromiseFactories() {
    describe('#testNative', testNative);
    describe('#testQ', testQ);
    describe('#testBluebird', testBluebird);

    var promiseBeingMade = new Promise(function(resolve) {
        resolve(true);
    });

    function testNative() {
        var treasury = new Treasury();

        it('should return a Promise', basicPromise);

        function basicPromise(done) {
            // arrange
            // act
            var result = treasury.invest(promiseBeingMade);

            // assert
            chai.assert.typeOf(result, 'Promise');

            done();
        }
    }

    function testQ() {
        it('should return a Q Promise', basicPromise);

        function basicPromise(done) {
            // arrange
            var treasury = new Treasury({promiseFactory: require('q').Promise});

            // act
            var result = treasury.invest(promiseBeingMade);

            // assert
            chai.assert.typeOf(result, 'Promise');

            done();
        }
    }

    function testBluebird() {
        it('should return a Bluebird Promise', basicPromise);

        function basicPromise(done) {
            // arrange
            var treasury = new Treasury({promiseFactory: require('bluebird')});

            // act
            var result = treasury.invest(promiseBeingMade);

            // assert
            chai.assert.typeOf(result, 'Promise');

            done();
        }
    }
}
@@ -294,26 +294,78 @@
 var 
-promiseBeingMade =
+expected = 12345;%0A%0A    function samplePromisedValue() %7B%0A        return
  new
@@ -405,16 +405,20 @@
     
+    
 resolve(
 true
@@ -417,22 +417,36 @@
 lve(
-true
+expected
 );%0A    
+  
+  
 %7D);
+%0A    %7D
 %0A%0A  
@@ -475,48 +475,8 @@
 ) %7B%0A
-        var treasury = new Treasury();%0A%0A
     
@@ -547,36 +547,32 @@
 on basicPromise(
-done
 ) %7B%0A            
@@ -574,32 +574,75 @@
      // arrange%0A
+            var treasury = new Treasury();%0A
             // a
@@ -652,36 +652,30 @@
             
-var result =
+return
  treasury.in
@@ -679,36 +679,86 @@
 .invest(
-promiseBeingMade);%0A%0A
+samplePromisedValue)%0A                .then(function(result) %7B%0A        
         
@@ -775,32 +775,40 @@
 ert%0A            
+      
+  
 chai.assert.type
@@ -795,38 +795,37 @@
     chai.assert.
-typeOf
+equal
 (result, 'Promis
@@ -813,37 +813,35 @@
 ual(result, 
-'Promise'
+expected
 );%0A
-%0A
             
@@ -832,37 +832,37 @@
 d);%0A            
-done(
+    %7D
 );%0A        %7D%0A   
@@ -966,36 +966,32 @@
 on basicPromise(
-done
 ) %7B%0A            
@@ -1110,36 +1110,30 @@
             
-var result =
+return
  treasury.in
@@ -1137,36 +1137,85 @@
 .invest(
-promiseBeingMade);%0A%0A
+samplePromisedValue)%0A                .then(function(result) %7B%0A       
         
@@ -1210,32 +1210,33 @@
                 
+ 
 // assert%0A      
@@ -1221,32 +1221,40 @@
       // assert%0A
+        
             chai
@@ -1253,38 +1253,37 @@
     chai.assert.
-typeOf
+equal
 (result, 'Promis
@@ -1271,37 +1271,35 @@
 ual(result, 
-'Promise'
+expected
 );%0A
-%0A
             
@@ -1290,37 +1290,37 @@
 d);%0A            
-done(
+    %7D
 );%0A        %7D%0A   
@@ -1446,20 +1446,16 @@
 Promise(
-done
 ) %7B%0A    
@@ -1589,20 +1589,14 @@
     
-var result =
+return
  tre
@@ -1612,28 +1612,77 @@
 est(
-promiseBeingMade);%0A%0A
+samplePromisedValue)%0A                .then(function(result) %7B%0A       
     
@@ -1681,32 +1681,33 @@
                 
+ 
 // assert%0A      
@@ -1692,32 +1692,40 @@
       // assert%0A
+        
             chai
@@ -1736,14 +1736,13 @@
 ert.
-typeOf
+equal
 (res
@@ -1750,21 +1750,19 @@
 lt, 
-'Promise'
+expected
 );%0A
-%0A
     
@@ -1773,13 +1773,13 @@
     
-done(
+    %7D
 );%0A 

refactor promise integration tests