epl-fixtures
Version:
Fixtures for Premier League clubs
101 lines (82 loc) • 2.99 kB
JavaScript
;
const fs = require('fs');
const path = require('path');
const chai = require('chai');
const expect = require('chai').expect;
const cache = require('../src/cache');
const Fixtures = require('../src/fixtures');
const fixtures = new Fixtures;
describe('Delete cache before running tests', function () {
before(function (done) {
fs.readdir(path.resolve(__dirname, '../cache/'), function (err, files) {
files.forEach(file => {
if (file !== '.gitkeep') {
fs.unlink(path.resolve(__dirname, '../cache/' + file));
}
});
done();
});
});
it('cache should only contain .gitkeep file', function () {
const filesAfterDeletion = fs.readdirSync(path.resolve(__dirname, '../cache/'));
expect(filesAfterDeletion).to.be.instanceof(Array);
expect(filesAfterDeletion.length).to.be.equal(1);
expect(filesAfterDeletion[0]).to.be.equal('.gitkeep');
});
});
describe('All clubs', function () {
let allClubsFixtures = [];
before(function (done) {
fixtures.all(function (err, matches) {
allClubsFixtures = matches;
done();
});
});
it('contains all matches in an array', function () {
expect(allClubsFixtures).to.be.instanceof(Array);
});
it('contains multiple clubs', function () {
const first = allClubsFixtures[0].clubs[0];
const second = allClubsFixtures[1].clubs[0];
expect(first).to.not.equal(second);
});
it('contains time, clubs, location, date and competition, userLocaleTime', function () {
expect(allClubsFixtures[0]).to.have.property('time');
expect(allClubsFixtures[0]).to.have.property('clubs');
expect(allClubsFixtures[0]).to.have.property('location');
expect(allClubsFixtures[0]).to.have.property('date');
expect(allClubsFixtures[0]).to.have.property('competition');
expect(allClubsFixtures[0]).to.have.property('userLocaleTime');
});
});
describe('Specific club, Liverpool', function () {
let clubFixtures = [];
before(function (done) {
fixtures.club('liverpool', function (err, matches) {
clubFixtures = matches;
done();
});
});
it('contains all matches in an array', function () {
expect(clubFixtures).to.be.instanceof(Array);
});
it('contains only matches for given club', function () {
const liverpoolMatches = clubFixtures.filter(function (match) {
if (match.clubs[0] === 'Liverpool' || match.clubs[1] === 'Liverpool') {
return match;
}
});
expect(clubFixtures.length).to.be.equal(liverpoolMatches.length);
});
});
describe('Caching', function () {
it('should have cached the "ALL" request', function () {
expect(cache.isCached('ALL')).to.be.equal(true);
});
it('should have cached the "Liverpool" (Club ID: 14) request', function () {
expect(cache.isCached(14)).to.be.equal(true);
});
it('should not have cached the "Arsenal" (Club ID: 3) request', function () {
expect(cache.isCached(3)).to.be.equal(false);
});
});