'use strict'; const pkg = require('../package.json'); const fs = require('graceful-fs'); const business = require('../index.js'); const path = require('path'); const chai = require('chai'); const expect = chai.expect; function initDocObject () { return { corpusName: 'hal', cartoType: 'conditor:hal', corpusResources: '/applis/corhal/loadistex/corpus-resources', halHarvestModifiedDateFrom: '2021-11-21T00:00:00.000Z', halHarvestModifiedDateTo: '2021-11-21T06:00:00.000Z', corpusOutput: '/applis/corhal/corpusOutput' }; } process.env.CORPUSES_ROOT = path.join(__dirname, 'data'); let harvestPath; describe(pkg.name + '/index.js', function () { before(function () { harvestPath = path.join(process.env.CORPUSES_ROOT, 'hal', 'hal-20211121-to-20211121'); if (fs.existsSync(harvestPath)) { fs.rmdirSync(harvestPath, { recursive: true }); } }); describe('Test succès de moissonnage :', function () { this.timeout(600000); it('Le docObject devrait contenir le corpusRoot', function (done) { const docObject = initDocObject(); business.doTheJob(docObject, function () { expect(docObject.corpusRoot).to.equal(harvestPath); const pathExist = fs.existsSync(docObject.corpusRoot); expect(pathExist).to.equal(true); fs.rmdirSync(harvestPath, { recursive: true }); done(); }); }); }); describe('Test échec de moissonnage :', function () { this.timeout(600000); it('Si le corpusRoot exist déjà', function (done) { const docObject = initDocObject(); docObject.halHarvestModifiedDateFrom = '2021-10-20T00:00:00.000Z'; docObject.halHarvestModifiedDateTo = '2021-10-21T00:00:00.000Z'; const harvestPath = path.join(process.env.CORPUSES_ROOT, 'hal', 'hal-20211020-to-20211021'); fs.mkdirSync(harvestPath, { recursive: true }); business.doTheJob(docObject, function (err) { // harvest folder already exist expect(err.code).to.equal('FolderExistError'); fs.rmdirSync(harvestPath, { recursive: true }); done(); }); }); it('Si l\'API renvoie une erreur', function (done) { const docObject = initDocObject(); docObject.halHarvestModifiedDateFrom = '1020-10-20T00:00:00.000Z'; docObject.halHarvestModifiedDateTo = '1020-10-21T00:00:00.000Z'; // message d'erreur de l'api business.doTheJob(docObject, function (err) { expect(err.code).to.equal('FetchError'); done(); }); }); it('Si aucun résultat trouvé', function (done) { const docObject = initDocObject(); docObject.halHarvestModifiedDateFrom = '2050-10-20T00:00:00.000Z'; docObject.halHarvestModifiedDateTo = '2050-10-21T00:00:00.000Z'; business.doTheJob(docObject, function (err) { // no result found expect(err.code).to.equal('NoResultFound'); done(); }); }); }); });