Newer
Older
tdm-utils / test / run.js
/* global __dirname, require, process, it */
'use strict';

var pkg = require('../package.json'),
  myObject = require('../index.js'),
  TU = require('rd-tu'),
  fs = require('fs'),
  path = require('path');

// Données de test
var dataset = {
  "corpusManager": require('./dataset/in/data/corpusManager.json'),
  "graphs": require('./dataset/in/data/graphs.json')
};

// Mapping indiquant quelle fonction de test et quelles données utiliser pour chaque fonction
var wrapper = {
  "corpusManager": {
    "init": testOf_corpusManagerInit,
    "indexAll": testOf_indexAll,
  },
  "graphs": {
    "docToDoc": testOf_graphsDocToDoc,
  }
};

/**
 * Test de chaques fonctions de :
 * - corpusManager.
 *   - init()
 *   - harvest()
 *   - prepare()
 *   - indexAll()
 * - graphs.
 *   - docToDoc()
 */
TU.start({
  description: pkg.name + '/index.js',
  root: 'myObject',
  object: myObject,
  dataset: dataset,
  wrapper: wrapper
});

/**
 * Fonction de test à appliquée pour :
 * - corpusManager.init()
 */
function testOf_corpusManagerInit(fn, item, cb) {
  return fn(item.arguments.input, item.arguments.output, function(err, res) {
    return cb(err);
  });
}

/**
 * Fonction de test à appliquée pour :
 * - corpusManager.indexAll()
 */
function testOf_indexAll(fn, item, cb) {
  return fn(item.arguments.directory, item.arguments.output, function(err, res) {
    return cb(err);
  });
}

/**
 * Fonction de test à appliquée pour :
 * - graphs.docToDoc()
 */
function testOf_graphsDocToDoc(fn, item, cb) {
  return fs.readFile(item.arguments.filePath, 'utf-8', function(err, res) {
    if (err) return cb(err);
    return fn(JSON.parse(res), item.arguments.options, function(err, res) {
      return cb(err);
    });
  });
}