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

136 lines
4.1 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 LT = require('../ncas/lt');
const failure = { 'fail':true };
const empty = {};
test.skip('LT::Extract Details from Index', async t => {
const rawhtml = fs.readFileSync('tests/data/lt/index.html');
const expectedJSON = jsonfile.readFileSync('tests/data/lt/index.json');
const ltScraper = new LT();
const output = await ltScraper.extractIndex(rawhtml);
t.deepEquals(output, expectedJSON, 'Extracted Details from Index');
t.end();
});
test.skip('LT:: Scrape a PS ', async t => {
t.test('LT::Extract Details from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ps_001.html');
const expectedJSON = jsonfile.readFileSync('tests/data/lt/ps_001.json');
const ltScraper = new LT();
const output = await ltScraper.extractEntityDetails(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
t.end();
});
t.test('LT::Extract intermediaries from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_001.html');
const expectedJSON = { 'lithuania': [ 'MAXIMA LT, UAB' ] };
const ltScraper = new LT();
const output = await ltScraper.extractEntityIntermediaries(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted intermediaries Details from Page');
t.end();
});
t.test('LT::Extract contra-intermediaries from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_001.html');
const expectedJSON = { 'lithuania': [ 'MAXIMA LT, UAB' ] };
const ltScraper = new LT();
const output = await ltScraper.extractEntityIntermediaries(psDetail, 'item-contra-intermediaries');
t.deepEquals(output, expectedJSON, 'Extracted contra-intermediaries Details from Page');
t.end();
});
t.test('LT::Extract intermediaries from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_001.html');
const expectedJSON = { 'lithuania': [ 'Mokėjimo terminalų sistemos, UAB', '"Paysera LT", UAB' ] };
const ltScraper = new LT();
const output = await ltScraper.extractEntityIntermediaries(psDetail, 'item-intermediaries');
t.deepEquals(output, expectedJSON, 'Extracted intermediaries Details from Page');
t.end();
});
t.test('LT::Extract list from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_001.html');
const expectedJSON = [ 'Public List of Currency Exchange Operators' ];
const ltScraper = new LT();
const output = await ltScraper.extractEntityList(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted list Details from Page');
t.end();
});
t.test('LT::Extract activity from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_001.html');
const expectedJSON = [ { 'activity': 'Money remittance', 'from': '2011-02-24', 'to': '-' } ];
const ltScraper = new LT();
const output = await ltScraper.extractEntityActivity(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted activity Details from Page');
t.end();
});
t.test('LT::Extract foe-countries from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_002.html');
const expectedJSON = { 'poland': [ 'MONETA INTERNATIONAL UAB SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ODDZIAŁ W POLSCE' ] };
const ltScraper = new LT();
const output = await ltScraper.extractEntityIntermediaries(psDetail, 'foe-countries');
t.deepEquals(output, expectedJSON, 'Extracted foe-countries Details from Page');
t.end();
});
t.end();
});
test.test('LT::Extract fos-content from Page', async t => {
const psDetail = fs.readFileSync('tests/data/lt/ent_002.html');
const expectedJSON = failure;
const ltScraper = new LT();
const output = await ltScraper.extractEntityFOSContent(psDetail);
console.log(JSON.stringify(output));
t.deepEquals(output, expectedJSON, 'Extracted fos-content Details from Page');
t.end();
});