334 lines
9.6 KiB
JavaScript
334 lines
9.6 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 Netherlands = require('../ncas/nl');
|
|
|
|
const nlScraper = new Netherlands();
|
|
|
|
const failure = { 'fail':true };
|
|
const empty = {};
|
|
|
|
test('NL:: Scrape a Payment Instititute', async t => {
|
|
const piDetail001 = fs.readFileSync('tests/data/nl/pi_001.html');
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_001_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_001_activity.json');
|
|
|
|
const output = await nlScraper.extractActivity(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.skip('NL::Full scrape', async t => {
|
|
const paymentSevices = jsonfile.readFileSync('tests/data/nl/paymentServices.json');
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_001_combo.json');
|
|
|
|
nlScraper.path = 'tests/sink';
|
|
nlScraper.paymentServices = Object.assign({}, paymentSevices);
|
|
|
|
await nlScraper._initBrowser();
|
|
nlScraper.page = await nlScraper.browser.newPage();
|
|
|
|
await nlScraper.page.goto(`data:text/html,${piDetail001}`, { 'waitUntil': 'networkidle0' });
|
|
|
|
const output = await nlScraper.processWFTBIDetail();
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
await nlScraper.page.close();
|
|
await nlScraper.browser.close();
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingOut from Page', async t => {
|
|
const expectedJSON = {};
|
|
|
|
const output = await nlScraper.extractPassportingOut(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingOut from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingIn from Page', async t => {
|
|
const expectedJSON = empty;
|
|
|
|
const output = await nlScraper.extractPassportingIn(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingIn from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: Scrape a Payment Instititute 002', async t => {
|
|
const piDetail002 = fs.readFileSync('tests/data/nl/pi_002.html');
|
|
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_002_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail002);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_002_activity.json');
|
|
|
|
const output = await nlScraper.extractActivity(piDetail002);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingOut from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_002_passportout.json');
|
|
|
|
const output = await nlScraper.extractPassportingOut(piDetail002);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingOut from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingIn from Page', async t => {
|
|
const expectedJSON = empty;
|
|
|
|
const output = await nlScraper.extractPassportingIn(piDetail002);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingIn from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: Scrape a Payment Instititute 003', async t => {
|
|
const piDetail003 = fs.readFileSync('tests/data/nl/pi_003.html');
|
|
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_003_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail003);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = [];
|
|
|
|
const output = await nlScraper.extractActivity(piDetail003);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingOut from Page', async t => {
|
|
const expectedJSON = empty;
|
|
|
|
const output = await nlScraper.extractPassportingOut(piDetail003);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingOut from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingIn from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/pi_003_passportIn.json');
|
|
|
|
const output = await nlScraper.extractPassportingIn(piDetail003);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingIn from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: Scrape a EMoney Service', async t => {
|
|
const piDetail001 = fs.readFileSync('tests/data/nl/em_001.html');
|
|
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/em_001_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/em_001_activity.json');
|
|
|
|
const output = await nlScraper.extractActivity(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.skip('NL::Full scrape', async t => {
|
|
const emoneyServices = jsonfile.readFileSync('tests/data/nl/emoneyServices.json');
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/em_001_combo.json');
|
|
|
|
nlScraper.path = 'tests/sink';
|
|
nlScraper.emoneyServices = Object.assign({}, emoneyServices);
|
|
|
|
await nlScraper._initBrowser();
|
|
nlScraper.page = await nlScraper.browser.newPage();
|
|
|
|
await nlScraper.page.goto(`data:text/html,${piDetail001}`, { 'waitUntil': 'networkidle0' });
|
|
|
|
const output = await nlScraper.processWFTEGDetail();
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
await nlScraper.page.close();
|
|
await nlScraper.browser.close();
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingIn from Page', async t => {
|
|
const expectedJSON = empty;
|
|
|
|
const output = await nlScraper.extractPassportingIn(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingIn from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: Scrape a EMoney Service 002', async t => {
|
|
const piDetail001 = fs.readFileSync('tests/data/nl/em_002.html');
|
|
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/em_002_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = [];
|
|
|
|
const output = await nlScraper.extractActivity(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract PassportingIn from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/em_002_passportIn.json');
|
|
|
|
const output = await nlScraper.extractPassportingIn(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted PassportingIn from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: Scrape a Credit Service', async t => {
|
|
const piDetail001 = fs.readFileSync('tests/data/nl/cs_001.html');
|
|
t.test('NL::Extract Details from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/cs_001_detail.json');
|
|
|
|
const output = await nlScraper.extractDetail(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Activitities from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/cs_001_activity.json');
|
|
|
|
const output = await nlScraper.extractActivity(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Activitities from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test('NL::Extract Passporting from Page', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/cs_001_passporting.json');
|
|
|
|
const output = await nlScraper.extractPassportingOut(piDetail001);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Passporting from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.skip('NL::Full scrape', async t => {
|
|
const creditServices = jsonfile.readFileSync('tests/data/nl/creditServices.json');
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/cs_001_combo.json');
|
|
|
|
const nlScraper = new Netherlands();
|
|
|
|
nlScraper.path = 'tests/sink';
|
|
nlScraper.creditServices = Object.assign({}, creditServices);
|
|
|
|
await nlScraper._initBrowser();
|
|
nlScraper.page = await nlScraper.browser.newPage();
|
|
|
|
await nlScraper.page.goto(`data:text/html,${piDetail001}`, { 'waitUntil': 'networkidle0' });
|
|
|
|
const output = await nlScraper.processWFTKFDetail();
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('NL:: DIN-329 defects', async t => {
|
|
const defect2AHTML = fs.readFileSync('tests/data/nl/din329_d2_01.html');
|
|
|
|
t.test('NL::Defect 2', async t => {
|
|
const expectedJSON = jsonfile.readFileSync('tests/data/nl/din329_d2_01.json');
|
|
|
|
const output = await nlScraper.extractDetail(defect2AHTML);
|
|
|
|
t.deepEquals(output, expectedJSON, 'Extracted Details from Page correctly');
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|