<commit_before>// Copyright 2014 Orchestrate, Inc.
/**
 * @fileoverview Test graph methods
 */

// Module Dependencies.
var assert = require('assert');
var db = require('./creds')();
var users = require('./testdata')('graph.test');
var Q = require('kew');
var util = require('util');

var r = function(collection, from, to, kind) {
  return db.newGraphBuilder()
    .create()
    .from(collection, from)
    .related(kind)
    .to(collection, to);
};

suite('Graph', function () {
  suiteSetup(function (done) {
    users.reset(function(res) {
      if (!res) {
        users.insertAll(done);
      } else {
        done(res);
      }
    });
  });

  test('Create graph relationships', function(done) {
     var relations = [r(users.collection, users.steve.email, users.kelsey.email, "friend"),
                      r(users.collection, users.kelsey.email, users.david.email, "friend")];

    Q.all(relations)
      .then(function (res) {
        assert.equal(2, res.length);
        for (var i in res) {
          assert.equal(204, res[i].statusCode);
        }
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

  test('Traverse graph relationship', function(done) {
    db.newGraphReader()
      .get()
      .from(users.collection, users.steve.email)
      .related('friend', 'friend')
      .then(function (res) {
        assert.equal(200, res.statusCode);
        assert.deepEqual(users.david, res.body.results[0].value);
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

  test('Delete graph relationship', function(done) {
    db.newGraphBuilder()
      .remove()
      .from(users.collection, users.kelsey.email)
      .related('friend')
      .to(users.collection, users.david.email)
      .then(function (res) {
        assert.equal(res.statusCode, 204);
        return db.newGraphReader()
          .get()
          .from(users.collection, users.steve.email)
          .related('friend', 'friend');
      })
      .then(function (res) {
        assert.equal(res.statusCode, 200);
        assert.equal(res.body.count, 0);
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

});
<commit_msg>Fix graph test after new graph relation changes.<commit_after>// Copyright 2014 Orchestrate, Inc.
/**
 * @fileoverview Test graph methods
 */

// Module Dependencies.
var assert = require('assert');
var db = require('./creds')();
var users = require('./testdata')('graph.test');
var Q = require('kew');
var util = require('util');

var r = function(collection, from, to, kind) {
  return db.newGraphBuilder()
    .create()
    .from(collection, from)
    .related(kind)
    .to(collection, to);
};

suite('Graph', function () {
  suiteSetup(function (done) {
    users.reset(function(res) {
      if (!res) {
        users.insertAll(done);
      } else {
        done(res);
      }
    });
  });

  test('Create graph relationships', function(done) {
     var relations = [r(users.collection, users.steve.email, users.kelsey.email, "friend"),
                      r(users.collection, users.kelsey.email, users.david.email, "friend")];

    Q.all(relations)
      .then(function (res) {
        assert.equal(2, res.length);
        for (var i in res) {
          assert.equal(201, res[i].statusCode);
        }
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

  test('Traverse graph relationship', function(done) {
    db.newGraphReader()
      .get()
      .from(users.collection, users.steve.email)
      .related('friend', 'friend')
      .then(function (res) {
        assert.equal(200, res.statusCode);
        assert.deepEqual(users.david, res.body.results[0].value);
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

  test('Delete graph relationship', function(done) {
    db.newGraphBuilder()
      .remove()
      .from(users.collection, users.kelsey.email)
      .related('friend')
      .to(users.collection, users.david.email)
      .then(function (res) {
        assert.equal(res.statusCode, 204);
        return db.newGraphReader()
          .get()
          .from(users.collection, users.steve.email)
          .related('friend', 'friend');
      })
      .then(function (res) {
        assert.equal(res.statusCode, 200);
        assert.equal(res.body.count, 0);
        done();
      })
      .fail(function (res) {
        done(res);
      });
  });

});

{'fraction_non_alphanumeric': 0.16923764811088754, 'fraction_numerical': 0.008495416946121171, 'mean_word_length': 2.3165307635285397, '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': '4582111', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1389, 'n_words': 271}