obdfcascrape/tests/scrape.lu.js
Martin Donnelly be5d3eae07 init
2019-05-05 20:13:56 +01:00

103 lines
2.9 KiB
JavaScript

const tape = require('tape');
const _test = require('tape-promise').default; // <---- notice 'default'
const test = _test(tape); // decorate tape
const fs = require('fs');
const jsonfile = require('jsonfile');
const cheerio = require('cheerio');
const path = require('path');
const Lux = require('../ncas/lu');
const sourcePath = path.join(__dirname, '/data/lu/');
const luScraper = new Lux();
const StaticServer = require('static-server');
const failure = { 'fail':true };
var server = new StaticServer({
'rootPath': sourcePath, // required, the root of the server file tree
'port': 7357, // required, the port to listen
'name': 'my-http-server', // optional, will set "X-Powered-by" HTTP header
// 'host': '10.0.0.100', // optional, defaults to any interface
'cors': '*', // optional, defaults to undefined
'followSymlink': true, // optional, defaults to a 404 error
'templates': {
'index': 'foo.html', // optional, defaults to 'index.html'
'notFound': '404.html' // optional, defaults to undefined
}
});
server.start(function () {
console.log('Server listening to', server.port);
console.log('Serving', server.rootPath);
});
test.skip('LUX:: Handle Menu', async t => {
t.test('🇱🇺::Extract status bar details', async t => {
const psDetail = fs.readFileSync('tests/data/lu/ps_001.html');
const expectedJSON = jsonfile.readFileSync('tests/data/lu/ps_001.json');
const $ = cheerio.load(psDetail);
const output = await luScraper.extractBarDetails($);
t.deepEquals(output, expectedJSON, 'Extracted status bar from Page');
t.end();
});
t.test('🇱🇺::Deal with menu index', async t => {
const expectedJSON = failure; // jsonfile.readFileSync(`tests/data/lu/ps_001.json`);
await luScraper._initBrowser(false);
luScraper.paymentServices = {
'items': 0,
'links': [],
'step': 0,
'indexStep': 0,
'visited': false,
'done' : false,
'urls': ['https://supervisedentities.apps.cssf.lu/index.html?language=en#AdvancedSearch'],
'sections' : [],
'sectionLinks' : []
};
luScraper.page = await luScraper.browser.newPage();
await luScraper.page.goto('http://127.0.0.1:7357/ps_001.html#ResultResearch', { 'waitUntil': 'networkidle0' });
await luScraper.processEntityIndex(luScraper.paymentServices);
const output = {};
t.deepEquals(output, expectedJSON, 'Extracted status bar from Page');
t.end();
});
t.end();
});
test.test('LUX:: Process PS Entity', async t => {
t.test('🇱🇺::Extract entity details', async t => {
const psDetail = fs.readFileSync('tests/data/lu/ps_002.html');
const expectedJSON = jsonfile.readFileSync('tests/data/lu/ps_002.json');
// const $ = cheerio.load(psDetail);
const output = await luScraper.extractEntityDetails(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted entity details from Page');
t.end();
});
t.end();
});