'use strict';
import chai      from 'chai'
import cas       from 'chai-as-promised'
import Immutable from 'immutable'

chai.use(cas);
var expect = chai.expect;

import all from '../'

var mkPromise = function(val) {
  return Promise.resolve(val);
};


var mapLike = function(name) {
  return [
    'List'
  , 'Set'
  , 'OrderedSet'
  ].indexOf(name) < 0;
};

[
  'List'
, 'Set'
, 'OrderedSet'
, 'Map'
, 'OrderedMap'
// , 'Stack' // todo fix this
// , 'Seq'   // todo fix this
].forEach(function(name) {

  describe(`Immutable.${name}`, function() {
    it(`should return a ${name} of resolved values`, function(done) {

      var mutval  = mapLike(name) ? {a: "a", b: 2, c: "3" } : [1, 2, 3];
      var mutprom = mapLike(name) ? {a: "a", b: 2, c: Promise.resolve("3") } : [1, Promise.resolve(2), 3];

      var value = Immutable[name](mutval);
      var prom = Immutable[name](mutprom);

      all(prom)
        .then(function(res) {
          if ( !res instanceof Immutable[name] ) {
            return done(new Error(`should return ${name}: ${res}`));
          }

          if ( !Immutable.is(value, res) ) {
            console.log('expected', value);
            console.log('got', res);
            return done(new Error('should return correct values'));
          }

          return done();
        })
        .catch(function(err) {
          done(err);
        });
    });
  });

});

@@ -887,16 +887,23 @@
 %0A%0A      
+expect(
 all(prom
@@ -903,16 +903,20 @@
 ll(prom)
+).to
 %0A       
@@ -922,48 +922,53 @@
   .t
-hen(function(res) %7B%0A          if ( !res 
+o.be.fulfilled%0A        .and.eventually.be.an.
 inst
@@ -973,17 +973,17 @@
 stanceof
- 
+(
 Immutabl
@@ -989,30 +989,26 @@
 le%5Bname%5D
- ) %7B%0A 
+)%0A
         
    retur
@@ -1003,385 +1003,107 @@
     
-   return done(new Error(%60should return $%7Bname%7D: $%7Bres%7D%60));%0A          %7D%0A%0A          if ( !Immutable.is(value, res) ) %7B%0A            console.log('expected', value);%0A            console.log('got', res);%0A            return done(new Error('should return correct values'));%0A          %7D%0A%0A          return done();%0A        %7D)%0A        .catch(function(err) %7B%0A          done(err);%0A        %7D
+.and.eventually.satisfy(function(res) %7B return Immutable.is(res, value) %7D)%0A        .and.notify(done
 );%0A 

improve test readability for immutable