0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 06:32:39 +00:00

Starting on the brew card

This commit is contained in:
Scott Tolksdorf
2017-05-29 23:39:59 -04:00
parent fa203047da
commit 380bbd661f
17 changed files with 137 additions and 77 deletions

View File

@@ -7,7 +7,7 @@ const config = require('nconf');
const app = require('app.js');
const DB = require('db.js');
const BrewData = require('brew.data.js');
const BrewGen = require('./brew.gen.js');
const SampleBrews = require('./sample_brews.js');
const Error = require('error.js');
@@ -25,7 +25,7 @@ describe('Brew API', () => {
before('Connect DB', DB.connect);
before('Clear DB', BrewData.removeAll);
before('Populate brews', ()=>{
return BrewGen.populateDB(BrewGen.static());
return SampleBrews.populateDB(SampleBrews.static());
});
describe('Create', () => {
it('creates a new brew', () => {
@@ -57,7 +57,7 @@ describe('Brew API', () => {
describe('Update', () => {
it('updates an existing brew', () => {
const storedBrew = BrewGen.get('BrewA');
const storedBrew = SampleBrews.get('BrewA');
return request(app)
.put(`/api/brew/${storedBrew.editId}`)
.send({ text : 'New Text' })
@@ -72,7 +72,7 @@ describe('Brew API', () => {
});
it('adds the user as author', () => {
const storedBrew = BrewGen.get('BrewA');
const storedBrew = SampleBrews.get('BrewA');
return request(app)
.put(`/api/brew/${storedBrew.editId}`)
.set('Cookie', `nc_session=${UserXToken}`)
@@ -85,7 +85,7 @@ describe('Brew API', () => {
});
});
it('should throw error on bad edit id', ()=>{
const storedBrew = BrewGen.get('BrewA');
const storedBrew = SampleBrews.get('BrewA');
return request(app)
.put(`/api/brew/BADEDITID`)
.send({ text : 'New Text' })
@@ -95,7 +95,7 @@ describe('Brew API', () => {
describe('Remove', () => {
it('should removes a brew', ()=>{
const storedBrew = BrewGen.get('BrewA');
const storedBrew = SampleBrews.get('BrewA');
return request(app)
.del(`/api/brew/${storedBrew.editId}`)
.send()
@@ -116,7 +116,7 @@ describe('Brew API', () => {
before('Connect DB', DB.connect);
before('Clear DB', BrewData.removeAll);
before('Populate brews', ()=>{
return BrewGen.populateDB(BrewGen.static());
return SampleBrews.populateDB(SampleBrews.static());
});
it('should be able to search for all published brews', ()=>{
@@ -187,7 +187,7 @@ describe('Brew API', () => {
.expect(200)
.then((res) => {
const result = res.body;
const brewCount = _.size(BrewGen.static());
const brewCount = _.size(SampleBrews.static());
result.total.should.be.equal(brewCount);
result.brews.length.should.be.equal(brewCount);
result.brews[0].should.have.property('editId');
@@ -199,7 +199,7 @@ describe('Brew API', () => {
before('Connect DB', DB.connect);
before('Clear DB', BrewData.removeAll);
before('Populate brews', ()=>{
return BrewGen.populateDB(BrewGen.static());
return SampleBrews.populateDB(SampleBrews.static());
});
it('should be able to query brews for a specific user', ()=>{

View File

@@ -6,20 +6,20 @@ let PopulatedBrews = {};
module.exports = {
//TODO: Add in a generator for old brews to test the old rendering code
random : (num = 20)=>{
return _.times(num, ()=>{
//TODO: Build better generator, use new snippets?
return {
title : 'BrewA',
description : '',
text : '',
authors : _.sampleSize(['userA','userB','userC','userD'], _.random(0, 3)),
systems : _.sampleSize(['5e', '4e', '3.5e', 'Pathfinder'], _.random(0,2)),
views : _.random(0,1000),
published : !!_.random(0,1)
};
});
},
// random : (num = 20)=>{
// return _.times(num, ()=>{
// //TODO: Build better generator, use new snippets?
// return {
// title : 'BrewA',
// description : '',
// text : '',
// authors : _.sampleSize(['userA','userB','userC','userD'], _.random(0, 3)),
// systems : _.sampleSize(['5e', '4e', '3.5e', 'Pathfinder'], _.random(0,2)),
// views : _.random(0,1000),
// published : !!_.random(0,1)
// };
// });
// },
old : () => {
return [
{

View File

@@ -3,7 +3,7 @@ const _ = require('lodash');
const DB = require('db.js');
const BrewData = require('brew.data.js');
const BrewGen = require('./brew.gen.js');
const SampleBrews = require('./sample_brews.js');
//const Error = require('error.js');
@@ -12,7 +12,7 @@ describe('Brew Search', () => {
before('Connect DB', DB.connect);
before('Clear DB', BrewData.removeAll);
before('Populate brews', ()=>{
return BrewGen.populateDB(BrewGen.static());
return SampleBrews.populateDB(SampleBrews.static());
});
@@ -28,7 +28,7 @@ describe('Brew Search', () => {
it('should be able to search for all brews', ()=>{
return BrewData.search()
.then((result) => {
const brewCount = _.size(BrewGen.static());
const brewCount = _.size(SampleBrews.static());
result.total.should.be.equal(brewCount);
result.brews.length.should.be.equal(brewCount);
})
@@ -41,7 +41,7 @@ describe('Brew Search', () => {
limit : 2
})
.then((result) => {
result.total.should.be.equal(_.size(BrewGen.static()));
result.total.should.be.equal(_.size(SampleBrews.static()));
result.brews.length.should.be.equal(2);
})
});

View File

@@ -10,7 +10,7 @@ const config = require('nconf')
const Chai = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-subset'))
.use(require('./brew.gen.js').chaiPlugin);
.use(require('./sample_brews.js').chaiPlugin);
const log = require('loglevel');
log.setLevel(config.get('log_level'));