0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 10:52:46 +00:00

created a brew generator and chai plugin for easier testing

This commit is contained in:
Scott Tolksdorf
2017-01-27 18:38:09 -05:00
parent 8018442f25
commit a826aaffd9
6 changed files with 124 additions and 111 deletions

View File

@@ -3,59 +3,16 @@ const _ = require('lodash');
const DB = require('db.js');
const BrewData = require('brew.data.js');
const Error = require('error.js');
const ids = (brewIds) => {
return _.map(brewIds, (brewId) => {
return { editId : brews[brewId].editId };
});
}
const BrewGen = require('./brew.gen.js');
//const Error = require('error.js');
//TODO: Move this brew generator to test.init
const brews = {
BrewA : {
title : 'Brew-Alpha',
description : 'fancy',
authors : ['userA'],
systems : [],
views : 12,
published : false
},
BrewB : {
title : 'Brew-Beta',
description : 'very fancy',
authors : ['userA'],
systems : [],
views : 7,
published : true
},
BrewC : {
title : 'Brew-Charlie',
description : 'test',
authors : ['userA', 'userB'],
systems : [],
views : 0,
published : false
},
BrewD : {
title : 'Brew-Delta',
description : 'test super amazing brew for 5e. Geared for Rangers.',
authors : ['userC'],
systems : [],
views : 1,
published : true
}
};
describe('Brew Search', () => {
before('Connect DB', DB.connect);
before('Clear DB', BrewData.removeAll);
before('Populate brews', ()=>{
return Promise.all(_.map(brews, (brewData, id) => {
return BrewData.create(brewData)
.then((brew)=>{ brews[id] = brew; });
}));
return BrewGen.populateDB(BrewGen.static());
});
@@ -67,8 +24,9 @@ describe('Brew Search', () => {
it('should be able to search for all brews', ()=>{
return BrewData.search()
.then((result) => {
result.total.should.be.equal(_.size(brews));
result.brews.length.should.be.equal(_.size(brews));
const brewCount = _.size(BrewGen.static());
result.total.should.be.equal(brewCount);
result.brews.length.should.be.equal(brewCount);
})
});
});
@@ -122,7 +80,7 @@ describe('Brew Search', () => {
return BrewData.termSearch('Charlie')
.then((result) => {
result.total.should.be.equal(1);
result.brews.should.containSubset(ids(['BrewC']));
result.brews.should.have.brews('BrewC');
})
});
@@ -130,7 +88,7 @@ describe('Brew Search', () => {
return BrewData.termSearch('fancy')
.then((result) => {
result.total.should.be.equal(2);
result.brews.should.containSubset(ids(['BrewA', 'BrewB']));
result.brews.should.have.brews('BrewA', 'BrewB');
})
});
@@ -138,7 +96,7 @@ describe('Brew Search', () => {
return BrewData.termSearch('ranger 5e')
.then((result) => {
result.total.should.be.equal(1);
result.brews.should.containSubset(ids(['BrewD']));
result.brews.should.have.brews('BrewD');
})
});
@@ -153,7 +111,7 @@ describe('Brew Search', () => {
return BrewData.termSearch('Brew Beta fancy')
.then((result) => {
result.total.should.be.equal(1);
result.brews.should.containSubset(ids(['BrewB']));
result.brews.should.have.brews('BrewB');
});
});
it.skip('should not worry about the case of the terms', () => {
@@ -166,7 +124,7 @@ describe('Brew Search', () => {
return BrewData.userSearch('userA')
.then((result) => {
result.total.should.be.equal(3);
result.brews.should.containSubset(ids(['BrewA', 'BrewB', 'BrewC']));
result.brews.should.have.brews('BrewA', 'BrewB', 'BrewC');
});
});
it('should return nothing if provided a non-exsistent user', () => {