
var neo4j = require("../build/node/neo4j");

describe('session', function() {
  it('should expose basic run/subscribe ', function(done) {
    // Given
    var driver = neo4j.driver("neo4j://localhost");

    // When & Then
    var records = [];
    driver.session().run( "RETURN 1.0 AS a").subscribe( {
      onNext : function( record ) {
        records.push( record ); 
      },
      onCompleted : function( ) {
        expect( records.length ).toBe( 1 );
        expect( records[0]['a'] ).toBe( 1 );
        driver.close();
        done();
      }
    });
  });

  it('should expose basic run/then/then ', function(done) {
    // Given
    var driver = neo4j.driver("neo4j://localhost");
    // When & Then
    driver.session().run( "RETURN 1.0 AS a")
    .then( 
      function( records ) {
        expect( records.length ).toBe( 1 );
        expect( records[0]['a'] ).toBe( 1 );
      }
    ).then(
      function(records) {
        expect( records.length ).toBe( 1 );
        expect( records[0]['a'] ).toBe( 1 );
        done();
      }
    ).then( function() { driver.close(); })
  });

  it('should expose basic run/catch ', function(done) {
    // Given
    var driver = neo4j.driver("neo4j://localhost");
    // When & Then
    driver.session().run( "RETURN 1 AS").catch(
      function(error) {
        expect( error.fields.length).toBe(1);
        driver.close();
        done();
      }
    )
  });
});
@@ -1014,32 +1014,16 @@
 e( 1 );%0A
-        done();%0A
       %7D%0A
@@ -1062,16 +1062,24 @@
 close();
+ done();
  %7D)%0A  %7D)

Test done after close.