<commit_before>var tap = require("tap")
  , test = tap.test
  , plan = tap.plan
  , creature
  , resource;

test("load resource module", function (t) {
  resource = require('../');
  t.ok(resource, "object loaded")
  t.end()
});

test("load creature resource - with memory datasource", function (t) {
  creature = resource.use('creature');

  t.type(creature.config, 'object', 'configuration defined - creature.config is object');

  t.type(creature.methods, 'object', 'methods defined - creature.methods is object');
  t.type(creature.methods.create, 'function', 'methods defined - methods.create is function');
  t.type(creature.methods.get, 'function', 'methods defined - methods.get is function');
  t.type(creature.methods.find, 'function', 'methods defined - methods.find is function');
  t.type(creature.methods.destroy, 'function', 'methods defined - methods.destroy is function');

  t.type(creature.create, 'function', 'methods hoisted - creature.create is function');
  t.type(creature.get, 'function', 'methods hoisted - creature.get is function');
  t.type(creature.find, 'function', 'methods hoisted - creature.find is function');
  t.type(creature.destroy, 'function', 'methods hoisted - creature.destroy is function');

  t.end()
});

testDatasource({ type: 'memory' });
testDatasource({ type: 'fs' });
testDatasource({ type: 'couch', database: 'big-test' });

function testDatasource(config) {

  var creatures = [
    { id: 'korben', life: 10, type: 'dragon' },
    { id: 'hazel', life: 15, type: 'dragon' },
    { id: 'booboo', life: 10, type: 'unicorn' }
  ];

  test("persist creature to " + config.type + " datasource", function (t) {
    creature.persist(config);
    t.end();
  });

  test("create creatures - with " + config.type + " datasource", function (t) {
    t.plan(3);

    creatures.forEach(function (c) {
      creature.create(c, function (err) {
        t.error(err, 'created creature ' + c.id);
      });
    });  
  });

  test("find creatures with id korben - with " + config.type + " datasource", function (t) {
    creature.find({ where: { id: 'korben' }}, function (err, creatures) {
      t.error(err, 'found creatures');

      t.equal(creatures.length, 1, 'found one creature');
      t.end();
    });
  });

  test("find creatures with life 10 - with " + config.type + " datasource", function (t) {
    creature.find({ where: { life: 10 }}, function (err, creatures) {
      t.error(err, 'found creatures');

      t.equal(creatures.length, 2, 'found two creatures');
      t.end();
    });
  });

  test("find creatures with type dragon - with " + config.type + " datasource", function (t) {<commit_msg>[test] More asserts in test/persistence-find.js<commit_after>var tap = require("tap")
  , test = tap.test
  , plan = tap.plan
  , creature
  , resource;

test("load resource module", function (t) {
  resource = require('../');
  t.ok(resource, "object loaded")
  t.end()
});

test("load creature resource - with memory datasource", function (t) {
  creature = resource.use('creature');

  t.type(creature.config, 'object', 'configuration defined - creature.config is object');

  t.type(creature.methods, 'object', 'methods defined - creature.methods is object');
  t.type(creature.methods.create, 'function', 'methods defined - methods.create is function');
  t.type(creature.methods.get, 'function', 'methods defined - methods.get is function');
  t.type(creature.methods.find, 'function', 'methods defined - methods.find is function');
  t.type(creature.methods.destroy, 'function', 'methods defined - methods.destroy is function');

  t.type(creature.create, 'function', 'methods hoisted - creature.create is function');
  t.type(creature.get, 'function', 'methods hoisted - creature.get is function');
  t.type(creature.find, 'function', 'methods hoisted - creature.find is function');
  t.type(creature.destroy, 'function', 'methods hoisted - creature.destroy is function');

  t.end()
});

testDatasource({ type: 'memory' });
testDatasource({ type: 'fs' });
testDatasource({ type: 'couch', database: 'big-test' });

function testDatasource(config) {

  var creatures = [
    { id: 'korben', life: 10, type: 'dragon' },
    { id: 'hazel', life: 15, type: 'dragon' },
    { id: 'booboo', life: 10, type: 'unicorn' }
  ];

  test("persist creature to " + config.type + " datasource", function (t) {
    t.doesNotThrow(function () {
      creature.persist(config);
    }, 'persisted creature to ' + config.type);
    t.end();
  });

  test("create creatures - with " + config.type + " datasource", function (t) {
    t.plan(15);

    creatures.forEach(function (c) {
      creature.create(c, function (err) {
        t.error(err, 'created creature ' + c.id);
        creature.get(c.id, function (err, _c) {
          t.error(err, 'creature ' + c.id + ' exists');
          t.equal(_c.id, c.id, 'id for ' + c.id + ' is correct');
          t.equal(_c.type, c.type, 'type for ' + c.id + ' is correct');
          t.equal(_c.life, c.life, 'life for ' + c.id + ' is correct');
        });
      });
    });  
  });

  test("find creatures with id korben - with " + config.type + " datasource", function (t) {
    creature.find({ where: { id: 'korben' }}, function (err, creatures) {
      t.error(err, 'found creatures');

      t.equal(creatures.length, 1, 'found one creature');
      t.end();
    });
  });

  test("find creatures with life 10 - with " + config.type + " datasource", function (t) {
    creature.find({ where: { life: 10 }}, function (err, creatures) {
      t.error(err, 'found creatures');

      t.equal(creatures.length, 2, 'found two creatures');
      t.end();
    });
  });

  test("find creatures with type dragon - with " + config.type + " datasource", function (t) {
{'fraction_non_alphanumeric': 0.17479108635097493, 'fraction_numerical': 0.004700557103064067, 'mean_word_length': 3.463869463869464, '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': '1648795', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1832, 'n_words': 482}