Newer
Older
li-add-unpaywall / test / run.js
/* eslint-env mocha */

const pkg = require('../package.json');
const business = require('../index.js');
const { expect } = require('chai');

describe(pkg.name + '/index.js', () => {
  describe('#Vérification de l\'ajout des  enrichissement unpaywall au cas où:', () => {
    const unpaywallEnrichments = [];

    before(function (done) {
      const docObjects = [
        {
          idIstex: '0123456789012345678901234567890123456789',
          doi: '10.15282/ijame.14.4.2017.7.0368',
        },
        {
          idIstex: '1123456789012345678901234567890123456789',
          doi: '10.1016/S0168-583X(97)00741-6',
        },
        {
          idIstex: '2123456789012345678901234567890123456789',
          doi: '10.1002/abcdefedcba',
        },
        {
          idIstex: '2123456789012345678901234567890123456789',
          doi: '10.1145/1053468.1053470',
        },
      ];
      business.finalJob(docObjects, () => {
        for (const docObject of docObjects) {
          unpaywallEnrichments.push(docObject?.enrichments?.openAccess?.unpaywall);
        }
        done();
      });
    });

    it('Vérifications génériques du résultat', () => {
      expect(unpaywallEnrichments[0]).to.not.equal(undefined);
      expect(unpaywallEnrichments[1]).to.not.equal(undefined);
      expect(unpaywallEnrichments[2]).to.equal(undefined);
    });

    // Check result contain url
    it('L\'enrichissement contient un champs url', () => {
      expect(unpaywallEnrichments[0].isOa).to.equal(true);
      expect(unpaywallEnrichments[0].oaLocations.length).to.be.gte(0);
      expect(unpaywallEnrichments[0].oaLocations[0].url.indexOf('http')).to.be.equal(0);
      expect(unpaywallEnrichments[0].oaLocations[0].version).to.be.equal('publishedVersion');
      expect(unpaywallEnrichments[1].isOa).to.equal(false);
    });
  });
});