Newer
Older
indexation / test / run.js
@kieffer kieffer on 27 Feb 2017 1 KB v0
/* 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 = require('./dataset/in/data/dataset.json');

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

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

/**
 * Fonction de test à appliquée pour :
 * - 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);
    });
  });
}