From ee68db03b377159bb3b1b7b044b463187f37ecce Mon Sep 17 00:00:00 2001 From: Georgina Hoagland Date: Wed, 30 Aug 2017 16:01:08 -0400 Subject: [PATCH 1/2] updated the model test for db changes --- package.json | 2 ++ server/db/db.js | 2 +- test/db/chat.spec.js | 31 +++++++++++++++++++ test/db/deck.spec.js | 33 ++++++++++++-------- test/db/slide.spec.js | 71 +++++++++++++++++++++++++++++++------------ 5 files changed, 105 insertions(+), 34 deletions(-) create mode 100644 test/db/chat.spec.js diff --git a/package.json b/package.json index 6f353c8..d7581dd 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,8 @@ "babel-preset-stage-0": "^6.24.1", "babel-register": "^6.24.1", "chai": "^3.5.0", + "chai-properties": "^1.2.1", + "chai-things": "^0.2.0", "css-loader": "^0.26.1", "enzyme": "^2.8.2", "eslint": "^4.3.0", diff --git a/server/db/db.js b/server/db/db.js index abeda9c..ba996c9 100644 --- a/server/db/db.js +++ b/server/db/db.js @@ -3,7 +3,7 @@ const Sequelize = require('sequelize'); const db = new Sequelize( process.env.DATABASE_URL || 'postgres://localhost:5432/slydv', { logging: false, - } + }, ); module.exports = db; diff --git a/test/db/chat.spec.js b/test/db/chat.spec.js new file mode 100644 index 0000000..53a6891 --- /dev/null +++ b/test/db/chat.spec.js @@ -0,0 +1,31 @@ +/* global describe it */ +import chai from 'chai'; +import chaiProperties from 'chai-properties'; +import chaiThings from 'chai-things'; +import db from '../../server/db'; + +chai.use(chaiProperties); +chai.use(chaiThings); +const expect = chai.expect; +const Chat = db.model('chat'); + +describe('Chat Model', () => { + it('has text', () => { + const chat = Chat.build({ message: 'Hello World!' }); + expect(chat.message).to.equal('Hello World!'); + }); + + it('message cannot be null', () => { + const newChat = Chat.build(); + return newChat.validate() + .then(() => { + throw new Error('This is not the error you are looking for.'); + }) + .catch((err) => { + expect(err.errors).to.contain.a.thing.with.properties({ + path: 'message', + type: 'notNull Violation', + }); + }); + }); +}); diff --git a/test/db/deck.spec.js b/test/db/deck.spec.js index 8fe27a7..1a736a8 100644 --- a/test/db/deck.spec.js +++ b/test/db/deck.spec.js @@ -1,7 +1,6 @@ /* global describe beforeEach it */ -const { expect } = require('chai'); -const db = require('../../server/db'); - +import { expect } from 'chai'; +import db from '../../server/db'; const Deck = db.model('deck'); @@ -12,24 +11,32 @@ describe('Deck Model', () => { .then(() => Deck.create({ deckTitle: 'Such deck', viewable: true, - chats: 'chatty chat chat', + hasFooter: true, + footerText: 'by Footer McFooterson', })) .then((newDeck) => { deck = newDeck; }); }); - it('has the expected schema definitions', () => { - expect(Deck.attributes.deckTitle).to.be.an('object'); - expect(Deck.attributes.viewable).to.be.an('object'); - expect(Deck.attributes.chats).to.be.an('object'); - expect(Deck.attributes.userId).to.be.an('object'); - }); it('has a deckTitle', () => { expect(deck.deckTitle).to.equal('Such deck'); }); - it('is viewable', () => { + + it('can be viewable', () => { expect(deck.viewable).to.be.true; }); - it('has chats', () => { - expect(deck.chats).to.equal('chatty chat chat'); + + it('can have a footer and have that footer be viewable', () => { + expect(deck.hasFooter).to.be.true; + expect(deck.footerText).to.equal('by Footer McFooterson'); + }); + + it('an empty deck defaults to the expected values', () => { + Deck.create() + .then((newDeck) => { + expect(newDeck.deckTitle).to.equal('Untitled Deck'); + expect(newDeck.theme).to.equal('antique'); + expect(newDeck.hasFooter).to.be.false; + expect(newDeck.footerText).to.equal(''); + }); }); }); diff --git a/test/db/slide.spec.js b/test/db/slide.spec.js index 5b1a20a..6293c8c 100644 --- a/test/db/slide.spec.js +++ b/test/db/slide.spec.js @@ -1,8 +1,12 @@ /* global describe beforeEach it */ -const { expect } = require('chai'); -const db = require('../../server/db'); - +import chai from 'chai'; +import chaiProperties from 'chai-properties'; +import chaiThings from 'chai-things'; +import db from '../../server/db'; +chai.use(chaiProperties); +chai.use(chaiThings); +const expect = chai.expect; const Slide = db.model('slide'); describe('Slide Model', () => { @@ -11,33 +15,60 @@ describe('Slide Model', () => { return db.sync({ force: true }) .then(() => Slide.create({ title: 'What a slide', - text: 'Wow. Much text. Such slide. Amaze.', + firstText: 'Wow. Much text. Such slide. Amaze.', + secondText: 'MOAR TEXT', + codeText: 'console.log("This is a test");', template: 'repl', + positionInDeck: 1, + presenterNotes: 'These are __presenter notes__', })) .then((newSlide) => { slide = newSlide; }); }); - it('has the expected schema definitions', () => { - expect(Slide.attributes.title).to.be.an('object'); - expect(Slide.attributes.text).to.be.an('object'); - expect(Slide.attributes.template).to.be.an('object'); - expect(Slide.attributes.codeText).to.be.an('object'); - expect(Slide.attributes.isHead).to.be.an('object'); - expect(Slide.attributes.nextId).to.be.an('object'); - expect(Slide.attributes.prevId).to.be.an('object'); - }); - it('has a title', () => { expect(slide.title).to.equal('What a slide'); }); + + it('has text', () => { - expect(slide.text).to.equal('Wow. Much text. Such slide. Amaze.'); + expect(slide.firstText).to.equal('Wow. Much text. Such slide. Amaze.'); + expect(slide.secondText).to.equal('MOAR TEXT'); + expect(slide.codeText).to.equal('console.log("This is a test");'); + }); + + it('has a template which dafualts to single-pane', () => { + expect(slide.template).to.equal('repl'); + Slide.create({ positionInDeck: 1 }) + .then(newSlide => expect(newSlide.template).to.equal('single-pane')); + }); + + it('requires a positionInDeck property', () => { + const tempSlide = Slide.build(); + return tempSlide.validate() + .catch((err) => { + expect(err.errors).to.contain.a.thing.with.properties({ + path: 'positionInDeck', + type: 'notNull Violation', + }); + }); }); - it('isHead defaults to false', () => { - expect(slide.isHead).to.be.false; + + it('positionInDeck must be positive', () => { + const tempSlide = Slide.build({ positionInDeck: -1 }); + return tempSlide.validate() + .catch((err) => { + expect(err.errors).to.contain.a.thing.with.properties({ + path: 'positionInDeck', + type: 'Validation error', + }); + }); }); - it('prevId and nextId default to null', () => { - expect(slide.prevId).to.equal(null); - expect(slide.nextId).to.equal(null); + + it('empty titles default to Slide # + positionInDeck', () => { + Slide.create({ positionInDeck: 2 }) + .then((emptyTitleSlide) => { + expect(emptyTitleSlide.title).to.equal('Slide #2'); + }); }); }); + From b53d84890c672ee7db47acc1a4c459ab590646ff Mon Sep 17 00:00:00 2001 From: India Amos Date: Wed, 30 Aug 2017 17:25:05 -0400 Subject: [PATCH 2/2] TEST: Add explicit path to mocha, so that tests will run (for me, anyway) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7581dd..f0c5a80 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "start": "node server", "start-dev": "npm run build-client-watch & npm run start-server", "start-server": "NODE_ENV='development' nodemon server -e html,js,scss --ignore public", - "test": "NODE_ENV='test' DATABASE_URL='postgres://localhost:5432/slydv-test' mocha ./test/**/*.spec.js --compilers js:babel-register", + "test": "NODE_ENV='test' DATABASE_URL='postgres://localhost:5432/slydv-test' node_modules/mocha/bin/mocha ./test/**/*.spec.js --compilers js:babel-register", "seed": "node seed" }, "eslintConfig": {