Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion server/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
31 changes: 31 additions & 0 deletions test/db/chat.spec.js
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
});
33 changes: 20 additions & 13 deletions test/db/deck.spec.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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('');
});
});
});
71 changes: 51 additions & 20 deletions test/db/slide.spec.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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');
});
});
});