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

180 lines
5.5 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 LV = require('../ncas/lv');
const lvScraper = new LV();
const failure = { 'fail':true };
const empty = {};
test.test('Payment Services', async t => {
test.test('Latvia:: Process PS Entity 001', async t => {
const htmlFile = 'tests/data/lv/ent_001.html';
t.test('LV::Extract entity details', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_001_detail.json');
const output = await lvScraper.extractEntitySections(psDetail, 'div#featured-articles-title');
t.deepEquals(output, expectedJSON, 'Extracted entity details from Page');
t.end();
});
t.test('LV::Extract entity Market Segments', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = [ { 'marketSegment': 'Payment institutions' } ];
const output = await lvScraper.extractEntitySubSections(psDetail, 'h2:contains("Market segments")');
t.deepEquals(output, expectedJSON, 'Extracted entity Market Segments from Page');
t.end();
});
t.test('LV::Extract entity Related Persons', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = [{ 'nameFirstNameSurname': 'Igor Ivchenko', 'personalIdentificationNumber': 'Member of the Board' }];
const output = await lvScraper.extractEntitySubSections(psDetail, 'h2:contains("Related persons")');
t.deepEquals(output, expectedJSON, 'Extracted entity Related Persons from Page');
t.end();
});
t.test('LV::Extract entity Licenses', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_001_licenses.json');
const output = await lvScraper.extractEntityLicenses(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted entity Licenses from Page');
t.end();
});
t.end();
});
test.test('Latvia:: Process PS Entity 002', async t => {
const htmlFile = 'tests/data/lv/ent_002.html';
t.test('LV::Extract entity details', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_002_detail.json');
const output = await lvScraper.extractEntitySections(psDetail, 'div#featured-articles-title');
t.deepEquals(output, expectedJSON, 'Extracted entity details from Page');
t.end();
});
t.test('LV::Extract entity Market Segments', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = [ { 'marketSegment': 'Payment institutions' }, { 'marketSegment': 'Insurance Intermediaries' } ];
const output = await lvScraper.extractEntitySubSections(psDetail, 'h2:contains("Market segments")');
t.deepEquals(output, expectedJSON, 'Extracted entity Market Segments from Page');
t.end();
});
t.test('LV::Extract entity Related Persons', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_002_related.json');
const output = await lvScraper.extractEntitySubSections(psDetail, 'h2:contains("Related persons")');
t.deepEquals(output, expectedJSON, 'Extracted entity Related Persons from Page');
t.end();
});
t.test('LV::Extract entity Licenses', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = [];
const output = await lvScraper.extractEntityLicenses(psDetail);
t.deepEquals(output, expectedJSON, 'Extracted entity Licenses from Page');
t.end();
});
t.end();
});
test.test('Latvia:: Process PS Entity 003', async t => {
const htmlFile = 'tests/data/lv/ent_003.html';
t.test('LV::Extract entity details', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_003_detail.json');
const output = await lvScraper.extractEntitySections(psDetail, 'div#featured-articles-title');
t.deepEquals(output, expectedJSON, 'Extracted entity details from Page');
t.end();
});
t.end();
});
test.test('Latvia:: Process PS Entity 004', async t => {
const htmlFile = 'tests/data/lv/ent_004.html';
t.test('LV::Extract entity sanctions', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = jsonfile.readFileSync('tests/data/lv/ent_004_sanctions.json');
const output = await lvScraper.extractEntitySections(psDetail, 'h2:contains("Sanctions")');
t.deepEquals(output, expectedJSON, 'Extracted entity sanctions from Page');
t.end();
});
t.end();
});
test.test('Latvia:: Process CI Entity 005', async t => {
const htmlFile = 'tests/data/lv/ent_005.html';
t.test('LV::Extract entity sanctions', async t => {
const psDetail = fs.readFileSync(htmlFile);
const expectedJSON = [ { 'marketSegment': 'Credit institutions', 'telephone': '67081034', 'email': 'info@signetbank.com', 'website': 'http://www.signetbank.com/' }, { 'marketSegment': 'Investment service providers' } ];
const output = await lvScraper.extractEntitySubSections(psDetail, 'h2:contains("Market segments")');
t.deepEquals(output, expectedJSON, 'Extracted entity sanctions from Page');
t.end();
});
t.end();
});
t.end();
});