<commit_before>/* -*- Mode: Javascript; js-indent-level: 2 -*- */

var testDatabase = require('./util/database');
var db = require('../')(testDatabase.url);

var assert = require('assert');
var async = require('async');

describe('seraph#save, seraph#read', function() {
  it('should accept id of 0 on read', function(done) {
    db.read(0, function(err, data) {
      if (err)
        assert.equal(err.statusCode, 204); // neo4j gives 204 no content
      done();
    });
  });

  it('should accept id of 0 on save', function(done) {
    db.save({ id: 0, herp: "DERP" }, function(err, data) {
      if (err)
        assert.ok(err.statusCode); // not seraph error
      done();
    });
  });

  it('should handle alternative id property name', function(done) {
    function create(done) {
      db.save({ name: 'Jon', age: 23 }, function(err, user) {
        assert.ok(!err, err);
        assert.ok(typeof user.ponies !== 'undefined');
        assert.equal(user.name, 'Jon');
        assert.equal(user.age, 23);

        done(null, user.ponies);
      });
    }

    function read(userId, done) {
      db.read(userId, function(err, user) {
        assert.ok(!err, err);
        assert.equal(user.name, 'Jon');
        assert.equal(user.age, 23);
        done(null, user);
      });
    }

    var origId = db.options.id;
    db.options.id = "ponies";
    try {
      async.waterfall([create, read], function(err, res) {
        db.options.id = origId;
        done(err, res);
      });<commit_msg>save with label: add test for saving with label<commit_after>var testDatabase = require('./util/database');
var db = require('../')(testDatabase.url);
var uniqn = require('./util/ponies').uniqn;

var assert = require('assert');
var async = require('async');

describe('seraph#node', function() {
  it('should accept id of 0 on read', function(done) {
    db.read(0, function(err, data) {
      if (err)
        assert.equal(err.statusCode, 204); // neo4j gives 204 no content
      done();
    });
  });

  it('should accept id of 0 on save', function(done) {
    db.save({ id: 0, herp: "DERP" }, function(err, data) {
      if (err)
        assert.ok(err.statusCode); // not seraph error
      done();
    });
  });

  it('should save with a label', function(done) {
    var label = uniqn();
    db.save({name: 'Jon'}, label, function(err, node) {
      assert(!err);
      assert.equal(node.name, 'Jon');
      db.nodesWithLabel(label, function(err, nodes) {
        assert(!err);
        assert.deepEqual(nodes[0], node);
        done();
      });
    });
  });

  it('should handle alternative id property name', function(done) {
    function create(done) {
      db.save({ name: 'Jon', age: 23 }, function(err, user) {
        assert.ok(!err, err);
        assert.ok(typeof user.ponies !== 'undefined');
        assert.equal(user.name, 'Jon');
        assert.equal(user.age, 23);

        done(null, user.ponies);
      });
    }

    function read(userId, done) {
      db.read(userId, function(err, user) {
        assert.ok(!err, err);
        assert.equal(user.name, 'Jon');
        assert.equal(user.age, 23);
        done(null, user);
      });
    }

    var origId = db.options.id;
    db.options.id = "ponies";
    try {
      async.waterfall([create, read], function(err, res) {
        db.options.id = origId;
        done(err, res);
      });
{'fraction_non_alphanumeric': 0.1769436997319035, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 2.527310924369748, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2701133', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1081, 'n_words': 265}