{"size": 1045, "ext": "js", "max_stars_repo_path": "test/put.js", "max_stars_repo_name": "jhermsmeier/node-hexadb", "max_stars_repo_stars_event_min_datetime": "2015-04-02T11:19:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-08T16:10:09.000Z", "max_issues_repo_path": "test/put.js", "max_issues_repo_name": "jhermsmeier/node-hexadb", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/put.js", "max_forks_repo_name": "jhermsmeier/node-hexadb", "max_forks_repo_forks_event_min_datetime": "2017-05-27T01:36:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-27T01:36:45.000Z"}
{"max_stars_count": 11, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 21.7708333333, "max_line_length": 52, "alphanum_fraction": 0.4918660287}
var HexaDB = require( '..' )
var assert = require( 'assert' )

describe( 'Put', function() {
  
  var db = new HexaDB( require( 'memdb' )() )
  
  it( 'db#put', function( next ) {
    
    var triple = {
      subject: 'door',
      predicate: 'state',
      object: 'open',
    }
    
    db.put( triple, function( error ) {
      if( error ) return next( error )
      db.get([ 'door' ], function( error, result ) {
        if( error ) return next( error )
        assert.equal( result.length, 1 )
        assert.deepEqual( result[0], triple )
        next()
      })
    })
    
  })
  
  it( 'db#putStream', function( next ) {
    
    var ps = db.putStream()
    
    ps.once( 'finish', function() {
      db.get([ 'door' ], function( error, result ) {
        if( error ) return next( error )
        assert.equal( result.length, 4 )
        next()
      })
    })
    
    ps.write([ 'door', 'state', 'closed' ])
    ps.write([ 'door', 'state', 'half-closed' ])
    ps.write([ 'door', 'state', 'half-open' ])
    ps.end()
    
  })
  
})
