egypt-banks-scraper
Version:
Scrape exchange rates from Egypt banks
75 lines (64 loc) • 2.17 kB
JavaScript
import { expect } from 'chai';
import banks from '../src/banks';
import { getBrowser } from '../src/browser';
const {
describe,
it,
beforeAll,
afterAll,
} = global;
describe('Banks', async () => {
let browser = null;
// start browser
beforeAll(async () => {
browser = await getBrowser();
}, process.env.timeout);
// loop on each bank and test them
banks.forEach((Bank) => {
const bank = new Bank();
describe(bank.name.acronym, () => {
describe('Rates', async () => {
let rates = null;
// get bank rates before start testing
beforeAll(async () => {
rates = await bank.scrape(browser);
console.log('Test ', bank.name.acronym);
}, process.env.timeout);
// test rates != null
it('rates should not equal null', () => {
expect(rates).to.not.equal(null);
});
// test rates not empty
it('rates should not be empty', () => {
expect(rates.length).to.not.equal(0);
});
// test rates codes are strings and have 3 letters
it('code property in rates should be a string of 3 letters', () => {
rates.forEach((currencyRate) => {
expect(currencyRate.code).to.be.a('string');
expect(currencyRate).to.have.property('code').with.lengthOf(3);
// TODO check that code from currency iso list
});
});
// test buy rates are numbers and are >= 0
it('buy property in rates should be a positive number', () => {
rates.forEach((currencyRate) => {
expect(currencyRate.buy).to.be.a('number');
expect(currencyRate.buy).to.be.at.least(0);
});
});
// test sell rates are numbers and are >= 0
it('sell property in rates should be a positive number', () => {
rates.forEach((currencyRate) => {
expect(currencyRate.sell).to.be.a('number');
expect(currencyRate.buy).to.be.at.least(0);
});
});
});
});
});
// after finish all banks close browser
afterAll(async () => {
await browser.close();
});
});