From ba32a48c27898f724e906a8744edc646df3c8273 Mon Sep 17 00:00:00 2001 From: andygout Date: Mon, 30 Jan 2017 21:47:08 +0000 Subject: [PATCH 1/3] Add: Babel packages reqd for ES6 modules --- init.js | 3 +++ package.json | 4 +++- setup.js | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 init.js create mode 100644 setup.js diff --git a/init.js b/init.js new file mode 100644 index 00000000..7cbdafff --- /dev/null +++ b/init.js @@ -0,0 +1,3 @@ +require('./setup'); + +module.exports = require('./app'); diff --git a/package.json b/package.json index a4dc26c5..b2233065 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,14 @@ "description": "A database-driven site that provides listings for theatrical productions, playtexts and associated data.", "main": "app.js", "scripts": { - "start": "nodemon app", + "start": "nodemon init", "test": "find spec -name '*.spec.js' | xargs mocha -R spec" }, "author": "https://github.com/andygout", "license": "MS-RSL", "dependencies": { + "babel-plugin-transform-es2015-modules-commonjs": "^6.22.0", + "babel-register": "^6.22.0", "body-parser": "^1.10.2", "connect-flash": "~0.1.1", "dateformat": "^2.0.0", diff --git a/setup.js b/setup.js new file mode 100644 index 00000000..707bbcd9 --- /dev/null +++ b/setup.js @@ -0,0 +1,3 @@ +require('babel-register')({ + plugins: ["transform-es2015-modules-commonjs"] +}); From 0357979e918179564d9041a50d7abd381aa1dbd9 Mon Sep 17 00:00:00 2001 From: andygout Date: Mon, 30 Jan 2017 22:41:35 +0000 Subject: [PATCH 2/3] Implement: ES6 modules syntax --- app.js | 31 ++++++++-------- database/pool.js | 4 +-- database/query.js | 4 +-- dotenv.js | 3 ++ server/controllers/index.js | 9 +++-- server/controllers/productions.js | 32 +++++++++++------ server/controllers/theatres.js | 26 +++++++++----- server/lib/alert.js | 10 ++++-- server/lib/constants.js | 2 +- server/lib/get-page-data.js | 4 +-- server/lib/handle-model-response.js | 8 ++--- server/lib/handlebars-helpers/capitalise.js | 2 +- .../lib/handlebars-helpers/date-format-now.js | 4 +-- server/lib/handlebars-helpers/index.js | 24 ++++++++----- .../instance-naming-value.js | 4 +-- .../lib/handlebars-helpers/instance-route.js | 2 +- .../handlebars-helpers/model-lower-case.js | 2 +- server/lib/handlebars-helpers/model.js | 2 +- server/lib/handlebars-helpers/upper-case.js | 2 +- server/lib/model-naming-prop-map.js | 2 +- server/lib/prop-is-object.js | 2 +- server/lib/renew-top-level-values.js | 2 +- server/lib/sql-templates.js | 25 ++++++++----- server/lib/trim-strings.js | 4 +-- server/lib/validate-string.js | 4 +-- server/lib/verify-error-presence.js | 4 +-- server/models/production.js | 29 ++++++++------- server/models/theatre.js | 35 +++++++++---------- server/routes/index.js | 32 ++++++++--------- 29 files changed, 179 insertions(+), 135 deletions(-) create mode 100644 dotenv.js diff --git a/app.js b/app.js index 1172e556..ef02d77e 100644 --- a/app.js +++ b/app.js @@ -1,19 +1,18 @@ -require('dotenv').config(); - -const bodyParser = require('body-parser'); -const exphbs = require('express-handlebars'); -const express = require('express'); -const Handlebars = require('handlebars'); -const favicon = require('serve-favicon'); -const flash = require('connect-flash'); -const http = require('http'); -const logger = require('morgan'); -const path = require('path'); -const sassMiddleware = require('node-sass-middleware'); -const session = require('express-session'); - -const handlebarsHelpers = require('./server/lib/handlebars-helpers'); -const router = require('./server/routes'); +import _ from './dotenv'; +import bodyParser from 'body-parser'; +import exphbs from 'express-handlebars'; +import express from 'express'; +import Handlebars from 'handlebars'; +import favicon from 'serve-favicon'; +import flash from 'connect-flash'; +import http from 'http'; +import logger from 'morgan'; +import path from 'path'; +import sassMiddleware from 'node-sass-middleware'; +import session from 'express-session'; + +import * as handlebarsHelpers from './server/lib/handlebars-helpers'; +import router from './server/routes'; const app = express(); diff --git a/database/pool.js b/database/pool.js index c0aba08e..6f211be1 100644 --- a/database/pool.js +++ b/database/pool.js @@ -1,4 +1,4 @@ -const pg = require('pg'); +import pg from 'pg'; const config = { database: process.env.DEV_DATABASE_NAME @@ -6,4 +6,4 @@ const config = { const pool = new pg.Pool(config); -module.exports = pool; +export default pool; diff --git a/database/query.js b/database/query.js index 00bbbd09..d0790b12 100644 --- a/database/query.js +++ b/database/query.js @@ -1,6 +1,6 @@ -const pool = require('./pool'); +import pool from './pool'; -module.exports = function (queryData) { +export default function (queryData) { return new Promise(function (resolve, reject) { diff --git a/dotenv.js b/dotenv.js new file mode 100644 index 00000000..a31953a9 --- /dev/null +++ b/dotenv.js @@ -0,0 +1,3 @@ +import dotenv from 'dotenv'; + +dotenv.config({ silent: true }); diff --git a/server/controllers/index.js b/server/controllers/index.js index 61ec2c6e..93ae2354 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js @@ -1,2 +1,7 @@ -exports.productions = require('./productions'); -exports.theatres = require('./theatres'); +import * as productions from './productions'; +import * as theatres from './theatres'; + +export { + productions, + theatres +}; diff --git a/server/controllers/productions.js b/server/controllers/productions.js index 5560c570..1a5cbc70 100644 --- a/server/controllers/productions.js +++ b/server/controllers/productions.js @@ -1,9 +1,9 @@ -const Production = require('../models/production'); -const getAlert = require('../lib/alert').get; -const getPageData = require('../lib/get-page-data'); -const handleModelResponse = require('../lib/handle-model-response'); +import Production from '../models/production'; +import { getAlert } from '../lib/alert'; +import getPageData from '../lib/get-page-data'; +import handleModelResponse from '../lib/handle-model-response'; -exports.new = (req, res, next) => { +function newRoute (req, res, next) { const production = new Production(); @@ -13,7 +13,7 @@ exports.new = (req, res, next) => { }; -exports.create = (req, res, next) => { +function createRoute (req, res, next) { const production = new Production(req.body); @@ -29,7 +29,7 @@ exports.create = (req, res, next) => { }; -exports.edit = (req, res, next) => { +function editRoute (req, res, next) { const production = new Production(req.params); @@ -45,7 +45,7 @@ exports.edit = (req, res, next) => { }; -exports.update = (req, res, next) => { +function updateRoute (req, res, next) { const production = new Production(req.body); @@ -61,7 +61,7 @@ exports.update = (req, res, next) => { }; -exports.delete = (req, res, next) => { +function deleteRoute (req, res, next) { const production = new Production(req.body); @@ -77,7 +77,7 @@ exports.delete = (req, res, next) => { }; -exports.show = (req, res, next) => { +function showRoute (req, res, next) { const production = new Production(req.params); @@ -93,7 +93,7 @@ exports.show = (req, res, next) => { }; -exports.list = (req, res, next) => { +function listRoute (req, res, next) { return Production.list() .then(productions => { @@ -106,3 +106,13 @@ exports.list = (req, res, next) => { .catch(err => next(err)); }; + +export { + newRoute, + createRoute, + editRoute, + updateRoute, + deleteRoute, + showRoute, + listRoute +}; diff --git a/server/controllers/theatres.js b/server/controllers/theatres.js index 5e18e61f..aba0c7d1 100644 --- a/server/controllers/theatres.js +++ b/server/controllers/theatres.js @@ -1,9 +1,9 @@ -const Theatre = require('../models/theatre'); -const getAlert = require('../lib/alert').get; -const getPageData = require('../lib/get-page-data'); -const handleModelResponse = require('../lib/handle-model-response'); +import Theatre from '../models/theatre'; +import { getAlert } from '../lib/alert'; +import getPageData from '../lib/get-page-data'; +import handleModelResponse from '../lib/handle-model-response'; -exports.edit = (req, res, next) => { +function editRoute (req, res, next) { const theatre = new Theatre(req.params); @@ -19,7 +19,7 @@ exports.edit = (req, res, next) => { }; -exports.update = (req, res, next) => { +function updateRoute (req, res, next) { const theatre = new Theatre(req.body); @@ -35,7 +35,7 @@ exports.update = (req, res, next) => { }; -exports.delete = (req, res, next) => { +function deleteRoute (req, res, next) { const theatre = new Theatre(req.body); @@ -51,7 +51,7 @@ exports.delete = (req, res, next) => { }; -exports.show = (req, res, next) => { +function showRoute (req, res, next) { const theatre = new Theatre(req.params); @@ -67,7 +67,7 @@ exports.show = (req, res, next) => { }; -exports.list = (req, res, next) => { +function listRoute (req, res, next) { return Theatre.list() .then(theatres => { @@ -82,3 +82,11 @@ exports.list = (req, res, next) => { .catch(err => next(err)); }; + +export { + editRoute, + updateRoute, + deleteRoute, + showRoute, + listRoute +}; diff --git a/server/lib/alert.js b/server/lib/alert.js index d4655142..cb4a7b0d 100644 --- a/server/lib/alert.js +++ b/server/lib/alert.js @@ -1,8 +1,14 @@ -exports.set = (req, pageData) => { +function setAlert (req, pageData) { req.flash('text', pageData.alertText); req.flash('type', pageData.alertType); }; -exports.get = req => ({ text: req.flash('text'), type: req.flash('type') }); +function getAlert (req) { + + return { text: req.flash('text'), type: req.flash('type') }; + +}; + +export { setAlert, getAlert }; diff --git a/server/lib/constants.js b/server/lib/constants.js index d7612f9b..02b1e64c 100644 --- a/server/lib/constants.js +++ b/server/lib/constants.js @@ -1,4 +1,4 @@ -module.exports = { +export default { STRING_MIN_LENGTH: 1, STRING_MAX_LENGTH: 255 diff --git a/server/lib/get-page-data.js b/server/lib/get-page-data.js index 9a1f54d4..d64384af 100644 --- a/server/lib/get-page-data.js +++ b/server/lib/get-page-data.js @@ -1,4 +1,4 @@ -const modelNamingPropMap = require('./model-naming-prop-map'); +import modelNamingPropMap from './model-naming-prop-map'; const getModelName = instance => instance.constructor.name.toLowerCase(); @@ -43,7 +43,7 @@ const getAlertText = (model, instance, action) => { const getAlertType = instance => instance.hasError ? 'error' : 'success'; -module.exports = function (instance, action) { +export default function (instance, action) { const model = getModelName(instance); diff --git a/server/lib/handle-model-response.js b/server/lib/handle-model-response.js index c15ce0b7..8c6c8f3a 100644 --- a/server/lib/handle-model-response.js +++ b/server/lib/handle-model-response.js @@ -1,14 +1,14 @@ -const alert = require('./alert'); +import { getAlert, setAlert } from './alert'; -module.exports = function (req, res, data) { +export default function (req, res, data) { const page = data.page; - alert.set(req, page); + setAlert(req, page); data[page.modelName].hasError ? (page.action === 'create' || page.action === 'update') ? - res.render(`${page.modelRoute}/form`, Object.assign(data, { alert: alert.get(req) })) : + res.render(`${page.modelRoute}/form`, Object.assign(data, { alert: getAlert(req) })) : res.redirect(page.instanceRoute) : res.redirect(page.action !== 'delete' ? page.instanceRoute : '/'); diff --git a/server/lib/handlebars-helpers/capitalise.js b/server/lib/handlebars-helpers/capitalise.js index 05b11f24..33c79d19 100644 --- a/server/lib/handlebars-helpers/capitalise.js +++ b/server/lib/handlebars-helpers/capitalise.js @@ -1,4 +1,4 @@ -module.exports = function (string) { +export default function (string) { return string.charAt(0).toUpperCase() + string.substring(1); diff --git a/server/lib/handlebars-helpers/date-format-now.js b/server/lib/handlebars-helpers/date-format-now.js index e50cb065..923fc926 100644 --- a/server/lib/handlebars-helpers/date-format-now.js +++ b/server/lib/handlebars-helpers/date-format-now.js @@ -1,6 +1,6 @@ -const dateFormat = require('dateformat'); +import dateFormat from 'dateformat'; -module.exports = function(format) { +export default function(format) { return dateFormat(new Date(), format); diff --git a/server/lib/handlebars-helpers/index.js b/server/lib/handlebars-helpers/index.js index a445ca24..24911556 100644 --- a/server/lib/handlebars-helpers/index.js +++ b/server/lib/handlebars-helpers/index.js @@ -1,11 +1,17 @@ -module.exports = { - - capitalise: require('./capitalise'), - dateFormatNow: require('./date-format-now'), - instanceNamingValue: require('./instance-naming-value'), - instanceRoute: require('./instance-route'), - model: require('./model'), - modelLowerCase: require('./model-lower-case'), - upperCase: require('./upper-case') +import capitalise from './capitalise'; +import dateFormatNow from './date-format-now'; +import instanceNamingValue from './instance-naming-value'; +import instanceRoute from './instance-route'; +import model from './model'; +import modelLowerCase from './model-lower-case'; +import upperCase from './upper-case'; +export { + capitalise, + dateFormatNow, + instanceNamingValue, + instanceRoute, + model, + modelLowerCase, + upperCase }; diff --git a/server/lib/handlebars-helpers/instance-naming-value.js b/server/lib/handlebars-helpers/instance-naming-value.js index 1935ce70..dab9232c 100644 --- a/server/lib/handlebars-helpers/instance-naming-value.js +++ b/server/lib/handlebars-helpers/instance-naming-value.js @@ -1,6 +1,6 @@ -const modelNamingPropMap = require('../model-naming-prop-map'); +import modelNamingPropMap from '../model-naming-prop-map'; -module.exports = function (instance) { +export default function (instance) { const model = instance.constructor.name.toLowerCase(); diff --git a/server/lib/handlebars-helpers/instance-route.js b/server/lib/handlebars-helpers/instance-route.js index ff1769d3..2123b1f5 100644 --- a/server/lib/handlebars-helpers/instance-route.js +++ b/server/lib/handlebars-helpers/instance-route.js @@ -1,4 +1,4 @@ -module.exports = function (instance) { +export default function (instance) { return `/${instance.constructor.name.toLowerCase()}s/${instance.id}`; diff --git a/server/lib/handlebars-helpers/model-lower-case.js b/server/lib/handlebars-helpers/model-lower-case.js index c7384e47..c885598e 100644 --- a/server/lib/handlebars-helpers/model-lower-case.js +++ b/server/lib/handlebars-helpers/model-lower-case.js @@ -1,4 +1,4 @@ -module.exports = function (instance) { +export default function (instance) { return !Array.isArray(instance) ? instance.constructor.name.toLowerCase() : diff --git a/server/lib/handlebars-helpers/model.js b/server/lib/handlebars-helpers/model.js index d53ae292..cbc23cb0 100644 --- a/server/lib/handlebars-helpers/model.js +++ b/server/lib/handlebars-helpers/model.js @@ -1,4 +1,4 @@ -module.exports = function (instance) { +export default function (instance) { return !Array.isArray(instance) ? instance.constructor.name : diff --git a/server/lib/handlebars-helpers/upper-case.js b/server/lib/handlebars-helpers/upper-case.js index 24c7d017..d34d76b2 100644 --- a/server/lib/handlebars-helpers/upper-case.js +++ b/server/lib/handlebars-helpers/upper-case.js @@ -1,4 +1,4 @@ -module.exports = function (string) { +export default function (string) { return string.toUpperCase(); diff --git a/server/lib/model-naming-prop-map.js b/server/lib/model-naming-prop-map.js index e2b8656a..137147fc 100644 --- a/server/lib/model-naming-prop-map.js +++ b/server/lib/model-naming-prop-map.js @@ -1,4 +1,4 @@ -module.exports = { +export default { production: 'title', theatre: 'name' diff --git a/server/lib/prop-is-object.js b/server/lib/prop-is-object.js index b4bb585b..ba08bd69 100644 --- a/server/lib/prop-is-object.js +++ b/server/lib/prop-is-object.js @@ -1,4 +1,4 @@ -module.exports = function (instanceProp) { +export default function (instanceProp) { return instanceProp !== null && typeof instanceProp === 'object' && diff --git a/server/lib/renew-top-level-values.js b/server/lib/renew-top-level-values.js index 7640f19d..a1c6f881 100644 --- a/server/lib/renew-top-level-values.js +++ b/server/lib/renew-top-level-values.js @@ -1,4 +1,4 @@ -module.exports = function (instance, newValues) { +export default function (instance, newValues) { for (const prop in instance) { diff --git a/server/lib/sql-templates.js b/server/lib/sql-templates.js index 27efa1fd..b5146a8e 100644 --- a/server/lib/sql-templates.js +++ b/server/lib/sql-templates.js @@ -1,5 +1,5 @@ -const format = require('pg-format'); -const modelNamingPropMap = require('./model-naming-prop-map'); +import format from 'pg-format'; +import modelNamingPropMap from './model-naming-prop-map'; const selectColumnsMap = { productions: ` @@ -28,7 +28,7 @@ const createJoin = model => { }; -exports.select = (instance, opts) => { +function select (instance, opts) { const table = opts.table || getTableName(instance); const columns = opts.selectCols ? selectColumnsMap[table] : opts.select1 ? '1' : '*'; @@ -45,7 +45,7 @@ exports.select = (instance, opts) => { }; -exports.create = (instance, createValues) => { +function create (instance, createValues) { const table = getTableName(instance); const columns = []; @@ -68,7 +68,7 @@ exports.create = (instance, createValues) => { }; -exports.update = (instance, updateValues) => { +function update (instance, updateValues) { const table = getTableName(instance); const assignments = []; @@ -88,7 +88,7 @@ exports.update = (instance, updateValues) => { }; -exports.delete = instance => { +function deletion (instance) { const table = getTableName(instance); const model = getModelName(instance); @@ -101,7 +101,7 @@ exports.delete = instance => { }; -exports.createIfNotExists = instance => { +function createIfNotExists (instance) { const table = getTableName(instance); @@ -131,7 +131,7 @@ exports.createIfNotExists = instance => { }; -exports.checkIfExists = instance => { +function checkIfExists (instance) { const table = getTableName(instance); @@ -143,3 +143,12 @@ exports.checkIfExists = instance => { `; }; + +export { + select, + create, + update, + deletion, + createIfNotExists, + checkIfExists +}; diff --git a/server/lib/trim-strings.js b/server/lib/trim-strings.js index 843ed0c6..117f9139 100644 --- a/server/lib/trim-strings.js +++ b/server/lib/trim-strings.js @@ -1,4 +1,4 @@ -const propIsObject = require('./prop-is-object'); +import propIsObject from './prop-is-object'; const trimStrings = instance => { @@ -16,7 +16,7 @@ const trimStrings = instance => { }; -module.exports = function (instance) { +export default function (instance) { trimStrings(instance); diff --git a/server/lib/validate-string.js b/server/lib/validate-string.js index 5599a4fa..626a8dca 100644 --- a/server/lib/validate-string.js +++ b/server/lib/validate-string.js @@ -1,6 +1,6 @@ -const constants = require('../lib/constants'); +import constants from '../lib/constants'; -module.exports = function (stringValue, propName) { +export default function (stringValue, propName) { const stringErrors = []; if (stringValue.length < constants.STRING_MIN_LENGTH) stringErrors.push(`${propName} is too short`); diff --git a/server/lib/verify-error-presence.js b/server/lib/verify-error-presence.js index afe4ef98..67934ba3 100644 --- a/server/lib/verify-error-presence.js +++ b/server/lib/verify-error-presence.js @@ -1,4 +1,4 @@ -const propIsObject = require('./prop-is-object'); +import propIsObject from './prop-is-object'; const propHasErrors = (prop, instanceProp) => prop === 'errors' && @@ -22,7 +22,7 @@ const searchForErrors = instance => { }; -module.exports = function (instance) { +export default function (instance) { return searchForErrors(instance); diff --git a/server/models/production.js b/server/models/production.js index ed8aa5ee..972295af 100644 --- a/server/models/production.js +++ b/server/models/production.js @@ -1,16 +1,15 @@ -const query = require('../../database/query'); -const renewTopLevelValues = require('../lib/renew-top-level-values'); -const sqlTemplates = require('../lib/sql-templates'); -const trimStrings = require('../lib/trim-strings'); -const validateString = require('../lib/validate-string'); -const verifyErrorPresence = require('../lib/verify-error-presence'); +import query from '../../database/query'; +import renewTopLevelValues from '../lib/renew-top-level-values'; +import { select, create, update, deletion } from '../lib/sql-templates'; +import trimStrings from '../lib/trim-strings'; +import validateString from '../lib/validate-string'; +import verifyErrorPresence from '../lib/verify-error-presence'; +import Theatre from './theatre'; -module.exports = class Production { +export default class Production { constructor (props = {}) { - const Theatre = require('./theatre'); - this.id = props.id; this.title = props.title; this.pageTitleText = props.pageTitleText; @@ -52,7 +51,7 @@ module.exports = class Production { .then(([theatre] = theatre) => { const queryData = { - text: sqlTemplates.create(this, { title: this.title, theatre_id: theatre.id }), + text: create(this, { title: this.title, theatre_id: theatre.id }), isReqdResult: true }; @@ -72,7 +71,7 @@ module.exports = class Production { edit () { const queryData = { - text: sqlTemplates.select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), + text: select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), isReqdResult: true }; @@ -101,7 +100,7 @@ module.exports = class Production { .then(([theatre] = theatre) => { const queryData = { - text: sqlTemplates.update(this, { title: this.title, theatre_id: theatre.id }), + text: update(this, { title: this.title, theatre_id: theatre.id }), isReqdResult: true }; @@ -121,7 +120,7 @@ module.exports = class Production { delete () { const queryData = { - text: sqlTemplates.delete(this), + text: deletion(this), isReqdResult: true }; @@ -139,7 +138,7 @@ module.exports = class Production { show () { const queryData = { - text: sqlTemplates.select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), + text: select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), isReqdResult: true }; @@ -156,7 +155,7 @@ module.exports = class Production { static list () { - const text = sqlTemplates.select(this, { + const text = select(this, { table: 'productions', selectCols: true, join: 'theatre', diff --git a/server/models/theatre.js b/server/models/theatre.js index 24ef2989..6b99d029 100644 --- a/server/models/theatre.js +++ b/server/models/theatre.js @@ -1,11 +1,12 @@ -const query = require('../../database/query'); -const renewTopLevelValues = require('../lib/renew-top-level-values'); -const sqlTemplates = require('../lib/sql-templates'); -const trimStrings = require('../lib/trim-strings'); -const validateString = require('../lib/validate-string'); -const verifyErrorPresence = require('../lib/verify-error-presence'); +import query from '../../database/query'; +import renewTopLevelValues from '../lib/renew-top-level-values'; +import { select, update, deletion, createIfNotExists, checkIfExists } from '../lib/sql-templates'; +import trimStrings from '../lib/trim-strings'; +import validateString from '../lib/validate-string'; +import verifyErrorPresence from '../lib/verify-error-presence'; +import Production from './production'; -module.exports = class Theatre { +export default class Theatre { constructor (props = {}) { @@ -30,7 +31,7 @@ module.exports = class Theatre { validateUpdateInDb () { - const text = sqlTemplates.checkIfExists(this); + const text = checkIfExists(this); return query({ text }) .then(result => { @@ -43,7 +44,7 @@ module.exports = class Theatre { validateDeleteInDb () { - const text = sqlTemplates.select(this, { + const text = select(this, { select1: true, table: 'productions', where: true, @@ -63,12 +64,12 @@ module.exports = class Theatre { getShowData () { const theatre = query({ - text: sqlTemplates.select(this, { where: true }), + text: select(this, { where: true }), isReqdResult: true }); const productions = query({ - text: sqlTemplates.select(this, { table: 'productions', where: true, id: 'theatre_id' }) + text: select(this, { table: 'productions', where: true, id: 'theatre_id' }) }); return Promise.all([theatre, productions]) @@ -84,8 +85,6 @@ module.exports = class Theatre { renewValues (props = {}) { - const Production = require('./production'); - renewTopLevelValues(this, props); this.productions = props.productions ? props.productions.map(production => new Production(production)) : []; @@ -95,7 +94,7 @@ module.exports = class Theatre { create () { const queryData = { - text: sqlTemplates.createIfNotExists(this), + text: createIfNotExists(this), isReqdResult: true }; @@ -106,7 +105,7 @@ module.exports = class Theatre { edit () { const queryData = { - text: sqlTemplates.select(this, { where: true }), + text: select(this, { where: true }), isReqdResult: true }; @@ -141,7 +140,7 @@ module.exports = class Theatre { if (this.hasError) return Promise.resolve(this); const queryData = { - text: sqlTemplates.update(this, { name: this.name }), + text: update(this, { name: this.name }), isReqdResult: true }; @@ -172,7 +171,7 @@ module.exports = class Theatre { } const queryData = { - text: sqlTemplates.delete(this), + text: deletion(this), isReqdResult: true }; @@ -197,7 +196,7 @@ module.exports = class Theatre { static list () { - const text = sqlTemplates.select(this, { table: 'theatres', order: true }); + const text = select(this, { table: 'theatres', order: true }); return query({ text }) .then(theatresRows => { diff --git a/server/routes/index.js b/server/routes/index.js index 09b1f0fc..5326cb51 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,6 +1,6 @@ -const express = require('express'); -const methodOverride = require('method-override'); -const controllers = require('../controllers'); +import express from 'express'; +import methodOverride from 'method-override'; +import * as controllers from '../controllers'; const router = express.Router(); @@ -19,24 +19,24 @@ router.use(methodOverride(function (req, res) { })); // Home -router.get('/', controllers.productions.list); +router.get('/', controllers.productions.listRoute); // Productions -router.get('/productions/new', controllers.productions.new); -router.post('/productions', controllers.productions.create); -router.get('/productions/:id/edit', controllers.productions.edit); -router.post('/productions/:id', controllers.productions.update); -router.delete('/productions/:id', controllers.productions.delete); -router.get('/productions/:id', controllers.productions.show); +router.get('/productions/new', controllers.productions.newRoute); +router.post('/productions', controllers.productions.createRoute); +router.get('/productions/:id/edit', controllers.productions.editRoute); +router.post('/productions/:id', controllers.productions.updateRoute); +router.delete('/productions/:id', controllers.productions.deleteRoute); +router.get('/productions/:id', controllers.productions.showRoute); router.get('/productions', function (req, res) { res.redirect('/'); }); // Theatres -router.get('/theatres/:id/edit', controllers.theatres.edit); -router.post('/theatres/:id', controllers.theatres.update); -router.delete('/theatres/:id', controllers.theatres.delete); -router.get('/theatres/:id', controllers.theatres.show); -router.get('/theatres', controllers.theatres.list); +router.get('/theatres/:id/edit', controllers.theatres.editRoute); +router.post('/theatres/:id', controllers.theatres.updateRoute); +router.delete('/theatres/:id', controllers.theatres.deleteRoute); +router.get('/theatres/:id', controllers.theatres.showRoute); +router.get('/theatres', controllers.theatres.listRoute); -module.exports = router; +export default router; From ded5f1c9316e4b70b59d3a0c677a5ad2e4831170 Mon Sep 17 00:00:00 2001 From: andygout Date: Thu, 2 Feb 2017 22:12:39 +0000 Subject: [PATCH 3/3] Restructure: File directories to allow tests to run --- .gitignore | 1 + init.js | 3 --- package.json | 13 ++++++----- server/.babelrc | 6 +++++ server/app-dev.js | 2 ++ app.js => server/app.js | 12 +++++----- {database => server/database}/pool.js | 0 {database => server/database}/query.js | 0 dotenv.js => server/dotenv.js | 0 server/models/production.js | 16 +++++++------- server/models/theatre.js | 22 +++++++++---------- setup.js | 3 --- spec/server/controllers/productions.spec.js | 8 ++++--- spec/server/controllers/theatres.spec.js | 8 ++++--- spec/server/lib/get-page-data.spec.js | 6 ++--- .../lib/handlebars-helpers/capitalise.spec.js | 2 +- .../instance-naming-value.spec.js | 6 ++--- .../handlebars-helpers/instance-route.spec.js | 4 ++-- .../model-lower-case.spec.js | 4 ++-- .../lib/handlebars-helpers/model.spec.js | 4 ++-- .../lib/handlebars-helpers/upper-case.spec.js | 2 +- spec/server/lib/prop-is-object.spec.js | 2 +- spec/server/lib/renew-values.spec.js | 2 +- spec/server/lib/sql-templates.spec.js | 16 +++++++------- spec/server/lib/trim-strings.spec.js | 2 +- spec/server/lib/validate-string.spec.js | 4 ++-- spec/server/lib/verify-error-presence.spec.js | 2 +- spec/server/models/production.spec.js | 4 ++-- spec/server/models/theatre.spec.js | 6 ++--- 29 files changed, 85 insertions(+), 75 deletions(-) delete mode 100644 init.js create mode 100644 server/.babelrc create mode 100644 server/app-dev.js rename app.js => server/app.js (88%) rename {database => server/database}/pool.js (100%) rename {database => server/database}/query.js (100%) rename dotenv.js => server/dotenv.js (100%) delete mode 100644 setup.js diff --git a/.gitignore b/.gitignore index 1bca5bcf..748ca933 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env client/favicons client/public +dist/ node_modules/ diff --git a/init.js b/init.js deleted file mode 100644 index 7cbdafff..00000000 --- a/init.js +++ /dev/null @@ -1,3 +0,0 @@ -require('./setup'); - -module.exports = require('./app'); diff --git a/package.json b/package.json index b2233065..94422095 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,15 @@ "name": "theatrebase", "version": "0.0.0", "description": "A database-driven site that provides listings for theatrical productions, playtexts and associated data.", - "main": "app.js", + "main": "server/app-dev.js", "scripts": { - "start": "nodemon init", - "test": "find spec -name '*.spec.js' | xargs mocha -R spec" + "start": "nodemon server/app-dev.js", + "test": "find spec -name '*.spec.js' | xargs mocha -R spec", + "pretest": "babel server --out-dir dist --ignore app-dev.js" }, "author": "https://github.com/andygout", "license": "MS-RSL", "dependencies": { - "babel-plugin-transform-es2015-modules-commonjs": "^6.22.0", - "babel-register": "^6.22.0", "body-parser": "^1.10.2", "connect-flash": "~0.1.1", "dateformat": "^2.0.0", @@ -29,6 +28,10 @@ "serve-favicon": "^2.2.0" }, "devDependencies": { + "babel-cli": "^6.22.2", + "babel-plugin-add-module-exports": "^0.2.1", + "babel-plugin-transform-es2015-modules-commonjs": "^6.22.0", + "babel-register": "^6.22.0", "chai": "^3.5.0", "mocha": "^3.2.0", "node-mocks-http": "^1.5.4", diff --git a/server/.babelrc b/server/.babelrc new file mode 100644 index 00000000..cfc8aea4 --- /dev/null +++ b/server/.babelrc @@ -0,0 +1,6 @@ +{ + "plugins": [ + "add-module-exports", + "transform-es2015-modules-commonjs" + ] +} diff --git a/server/app-dev.js b/server/app-dev.js new file mode 100644 index 00000000..7fd3952d --- /dev/null +++ b/server/app-dev.js @@ -0,0 +1,2 @@ +require('babel-register'); +require('./app'); diff --git a/app.js b/server/app.js similarity index 88% rename from app.js rename to server/app.js index ef02d77e..7da9bf6c 100644 --- a/app.js +++ b/server/app.js @@ -11,8 +11,8 @@ import path from 'path'; import sassMiddleware from 'node-sass-middleware'; import session from 'express-session'; -import * as handlebarsHelpers from './server/lib/handlebars-helpers'; -import router from './server/routes'; +import * as handlebarsHelpers from './lib/handlebars-helpers'; +import router from './routes'; const app = express(); @@ -28,7 +28,7 @@ app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); -app.use(favicon(path.join(__dirname, 'client', 'favicons', 'favicon.ico'))); +app.use(favicon(path.join(__dirname, '../', 'client', 'favicons', 'favicon.ico'))); app.use(logger('dev')); @@ -38,14 +38,14 @@ app.use(flash()); app.use( sassMiddleware({ - src: path.join(__dirname, 'client', 'stylesheets'), - dest: path.join(__dirname, 'client', 'public'), + src: path.join(__dirname, '../', 'client', 'stylesheets'), + dest: path.join(__dirname, '../', 'client', 'public'), prefix: '/stylesheets', debug: true }) ); -app.use(express.static(path.join(__dirname, 'client', 'public'))); +app.use(express.static(path.join(__dirname, '../', 'client', 'public'))); app.use('/', router); diff --git a/database/pool.js b/server/database/pool.js similarity index 100% rename from database/pool.js rename to server/database/pool.js diff --git a/database/query.js b/server/database/query.js similarity index 100% rename from database/query.js rename to server/database/query.js diff --git a/dotenv.js b/server/dotenv.js similarity index 100% rename from dotenv.js rename to server/dotenv.js diff --git a/server/models/production.js b/server/models/production.js index 972295af..c11d5980 100644 --- a/server/models/production.js +++ b/server/models/production.js @@ -1,6 +1,6 @@ -import query from '../../database/query'; +import query from '../database/query'; import renewTopLevelValues from '../lib/renew-top-level-values'; -import { select, create, update, deletion } from '../lib/sql-templates'; +import * as sqlTemplates from '../lib/sql-templates'; import trimStrings from '../lib/trim-strings'; import validateString from '../lib/validate-string'; import verifyErrorPresence from '../lib/verify-error-presence'; @@ -51,7 +51,7 @@ export default class Production { .then(([theatre] = theatre) => { const queryData = { - text: create(this, { title: this.title, theatre_id: theatre.id }), + text: sqlTemplates.create(this, { title: this.title, theatre_id: theatre.id }), isReqdResult: true }; @@ -71,7 +71,7 @@ export default class Production { edit () { const queryData = { - text: select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), + text: sqlTemplates.select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), isReqdResult: true }; @@ -100,7 +100,7 @@ export default class Production { .then(([theatre] = theatre) => { const queryData = { - text: update(this, { title: this.title, theatre_id: theatre.id }), + text: sqlTemplates.update(this, { title: this.title, theatre_id: theatre.id }), isReqdResult: true }; @@ -120,7 +120,7 @@ export default class Production { delete () { const queryData = { - text: deletion(this), + text: sqlTemplates.deletion(this), isReqdResult: true }; @@ -138,7 +138,7 @@ export default class Production { show () { const queryData = { - text: select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), + text: sqlTemplates.select(this, { selectCols: true, join: 'theatre', where: true, id: 'productions.id' }), isReqdResult: true }; @@ -155,7 +155,7 @@ export default class Production { static list () { - const text = select(this, { + const text = sqlTemplates.select(this, { table: 'productions', selectCols: true, join: 'theatre', diff --git a/server/models/theatre.js b/server/models/theatre.js index 6b99d029..150ae2c7 100644 --- a/server/models/theatre.js +++ b/server/models/theatre.js @@ -1,6 +1,6 @@ -import query from '../../database/query'; +import query from '../database/query'; import renewTopLevelValues from '../lib/renew-top-level-values'; -import { select, update, deletion, createIfNotExists, checkIfExists } from '../lib/sql-templates'; +import * as sqlTemplates from '../lib/sql-templates'; import trimStrings from '../lib/trim-strings'; import validateString from '../lib/validate-string'; import verifyErrorPresence from '../lib/verify-error-presence'; @@ -31,7 +31,7 @@ export default class Theatre { validateUpdateInDb () { - const text = checkIfExists(this); + const text = sqlTemplates.checkIfExists(this); return query({ text }) .then(result => { @@ -44,7 +44,7 @@ export default class Theatre { validateDeleteInDb () { - const text = select(this, { + const text = sqlTemplates.select(this, { select1: true, table: 'productions', where: true, @@ -64,12 +64,12 @@ export default class Theatre { getShowData () { const theatre = query({ - text: select(this, { where: true }), + text: sqlTemplates.select(this, { where: true }), isReqdResult: true }); const productions = query({ - text: select(this, { table: 'productions', where: true, id: 'theatre_id' }) + text: sqlTemplates.select(this, { table: 'productions', where: true, id: 'theatre_id' }) }); return Promise.all([theatre, productions]) @@ -94,7 +94,7 @@ export default class Theatre { create () { const queryData = { - text: createIfNotExists(this), + text: sqlTemplates.createIfNotExists(this), isReqdResult: true }; @@ -105,7 +105,7 @@ export default class Theatre { edit () { const queryData = { - text: select(this, { where: true }), + text: sqlTemplates.select(this, { where: true }), isReqdResult: true }; @@ -140,7 +140,7 @@ export default class Theatre { if (this.hasError) return Promise.resolve(this); const queryData = { - text: update(this, { name: this.name }), + text: sqlTemplates.update(this, { name: this.name }), isReqdResult: true }; @@ -171,7 +171,7 @@ export default class Theatre { } const queryData = { - text: deletion(this), + text: sqlTemplates.deletion(this), isReqdResult: true }; @@ -196,7 +196,7 @@ export default class Theatre { static list () { - const text = select(this, { table: 'theatres', order: true }); + const text = sqlTemplates.select(this, { table: 'theatres', order: true }); return query({ text }) .then(theatresRows => { diff --git a/setup.js b/setup.js deleted file mode 100644 index 707bbcd9..00000000 --- a/setup.js +++ /dev/null @@ -1,3 +0,0 @@ -require('babel-register')({ - plugins: ["transform-es2015-modules-commonjs"] -}); diff --git a/spec/server/controllers/productions.spec.js b/spec/server/controllers/productions.spec.js index 3211991f..260e7450 100644 --- a/spec/server/controllers/productions.spec.js +++ b/spec/server/controllers/productions.spec.js @@ -4,7 +4,7 @@ const proxyquire = require('proxyquire'); const sinon = require('sinon'); require('sinon-as-promised'); -const Production = require('../../../server/models/production'); +const Production = require('../../../dist/models/production'); const alertFixture = require('../../fixtures/alert'); const dataListFixture = require('../../fixtures/data-list'); @@ -38,7 +38,7 @@ let response; let next; const createSubject = (stubs) => - proxyquire('../../../server/controllers/productions', { + proxyquire('../../../dist/controllers/productions', { '../models/production': stubs.ProductionModel, '../lib/get-page-data': stubs.getPageData }); @@ -66,7 +66,9 @@ const createInstance = (action, method, methodStub) => { const subject = createSubject({ ProductionModel, getPageData: getPageDataStub }); - return subject[method](request, response, next); + const controllerFunction = `${method}Route`; + + return subject[controllerFunction](request, response, next); }; diff --git a/spec/server/controllers/theatres.spec.js b/spec/server/controllers/theatres.spec.js index 0900b517..d7e468f9 100644 --- a/spec/server/controllers/theatres.spec.js +++ b/spec/server/controllers/theatres.spec.js @@ -4,7 +4,7 @@ const proxyquire = require('proxyquire'); const sinon = require('sinon'); require('sinon-as-promised'); -const Theatre = require('../../../server/models/theatre'); +const Theatre = require('../../../dist/models/theatre'); const alertFixture = require('../../fixtures/alert'); const dataListFixture = require('../../fixtures/data-list'); @@ -38,7 +38,7 @@ let response; let next; const createSubject = (stubs) => - proxyquire(`../../../server/controllers/theatres`, { + proxyquire(`../../../dist/controllers/theatres`, { '../models/theatre': stubs.TheatreModel, '../lib/get-page-data': stubs.getPageData }); @@ -59,7 +59,9 @@ const createInstance = (action, method, methodStub) => { const subject = createSubject({ TheatreModel, getPageData: getPageDataStub }); - return subject[method](request, response, next); + const controllerFunction = `${method}Route`; + + return subject[controllerFunction](request, response, next); }; diff --git a/spec/server/lib/get-page-data.spec.js b/spec/server/lib/get-page-data.spec.js index 1870610e..95d70993 100644 --- a/spec/server/lib/get-page-data.spec.js +++ b/spec/server/lib/get-page-data.spec.js @@ -1,8 +1,8 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const Production = require('../../../server/models/production'); -const Theatre = require('../../../server/models/theatre'); +const Production = require('../../../dist/models/production'); +const Theatre = require('../../../dist/models/theatre'); const stubs = { Production: null, @@ -20,7 +20,7 @@ const resetStubs = () => { }; -const subject = require('../../../server/lib/get-page-data'); +const subject = require('../../../dist/lib/get-page-data'); beforeEach(function () { diff --git a/spec/server/lib/handlebars-helpers/capitalise.spec.js b/spec/server/lib/handlebars-helpers/capitalise.spec.js index 6ab901c9..908f884a 100644 --- a/spec/server/lib/handlebars-helpers/capitalise.spec.js +++ b/spec/server/lib/handlebars-helpers/capitalise.spec.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const subject = require('../../../../server/lib/handlebars-helpers/capitalise'); +const subject = require('../../../../dist/lib/handlebars-helpers/capitalise'); describe('Capitalise handlebars helper', () => { diff --git a/spec/server/lib/handlebars-helpers/instance-naming-value.spec.js b/spec/server/lib/handlebars-helpers/instance-naming-value.spec.js index 8870cb12..ea806d0f 100644 --- a/spec/server/lib/handlebars-helpers/instance-naming-value.spec.js +++ b/spec/server/lib/handlebars-helpers/instance-naming-value.spec.js @@ -1,8 +1,8 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const Production = require('../../../../server/models/production'); -const Theatre = require('../../../../server/models/theatre'); +const Production = require('../../../../dist/models/production'); +const Theatre = require('../../../../dist/models/theatre'); const stubs = { Production: null, @@ -22,7 +22,7 @@ beforeEach(function () { }); -const subject = require('../../../../server/lib/handlebars-helpers/instance-naming-value'); +const subject = require('../../../../dist/lib/handlebars-helpers/instance-naming-value'); describe('Instance Naming Value handlebars helper', () => { diff --git a/spec/server/lib/handlebars-helpers/instance-route.spec.js b/spec/server/lib/handlebars-helpers/instance-route.spec.js index 06f6b54a..4848fe7d 100644 --- a/spec/server/lib/handlebars-helpers/instance-route.spec.js +++ b/spec/server/lib/handlebars-helpers/instance-route.spec.js @@ -1,13 +1,13 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const Production = require('../../../../server/models/production'); +const Production = require('../../../../dist/models/production'); const stubs = { Production: sinon.createStubInstance(Production) }; -const subject = require('../../../../server/lib/handlebars-helpers/instance-route'); +const subject = require('../../../../dist/lib/handlebars-helpers/instance-route'); describe('Instance Route handlebars helper', () => { diff --git a/spec/server/lib/handlebars-helpers/model-lower-case.spec.js b/spec/server/lib/handlebars-helpers/model-lower-case.spec.js index 6a799b0f..b8890c71 100644 --- a/spec/server/lib/handlebars-helpers/model-lower-case.spec.js +++ b/spec/server/lib/handlebars-helpers/model-lower-case.spec.js @@ -1,13 +1,13 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const Production = require('../../../../server/models/production'); +const Production = require('../../../../dist/models/production'); const stubs = { Production: sinon.createStubInstance(Production) }; -const subject = require('../../../../server/lib/handlebars-helpers/model-lower-case'); +const subject = require('../../../../dist/lib/handlebars-helpers/model-lower-case'); describe('Model Lower Case handlebars helper', () => { diff --git a/spec/server/lib/handlebars-helpers/model.spec.js b/spec/server/lib/handlebars-helpers/model.spec.js index 822e880f..91f4023d 100644 --- a/spec/server/lib/handlebars-helpers/model.spec.js +++ b/spec/server/lib/handlebars-helpers/model.spec.js @@ -1,13 +1,13 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const Production = require('../../../../server/models/production'); +const Production = require('../../../../dist/models/production'); const stubs = { Production: sinon.createStubInstance(Production) }; -const subject = require('../../../../server/lib/handlebars-helpers/model'); +const subject = require('../../../../dist/lib/handlebars-helpers/model'); describe('Model handlebars helper', () => { diff --git a/spec/server/lib/handlebars-helpers/upper-case.spec.js b/spec/server/lib/handlebars-helpers/upper-case.spec.js index a1cdf4e9..d0179ba8 100644 --- a/spec/server/lib/handlebars-helpers/upper-case.spec.js +++ b/spec/server/lib/handlebars-helpers/upper-case.spec.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const subject = require('../../../../server/lib/handlebars-helpers/upper-case'); +const subject = require('../../../../dist/lib/handlebars-helpers/upper-case'); describe('Upper Case handlebars helper', () => { diff --git a/spec/server/lib/prop-is-object.spec.js b/spec/server/lib/prop-is-object.spec.js index 2879e282..21c0dd8e 100644 --- a/spec/server/lib/prop-is-object.spec.js +++ b/spec/server/lib/prop-is-object.spec.js @@ -1,6 +1,6 @@ const expect = require('chai').expect; -const subject = require('../../../server/lib/prop-is-object'); +const subject = require('../../../dist/lib/prop-is-object'); describe('Prop Is Object module', () => { diff --git a/spec/server/lib/renew-values.spec.js b/spec/server/lib/renew-values.spec.js index 572ca52d..502cb5df 100644 --- a/spec/server/lib/renew-values.spec.js +++ b/spec/server/lib/renew-values.spec.js @@ -3,7 +3,7 @@ const expect = require('chai').expect; let instance; let newValues; -const subject = require('../../../server/lib/renew-top-level-values'); +const subject = require('../../../dist/lib/renew-top-level-values'); describe('Renew Top Level Values module', () => { diff --git a/spec/server/lib/sql-templates.spec.js b/spec/server/lib/sql-templates.spec.js index 8dd4bf76..412170a1 100644 --- a/spec/server/lib/sql-templates.spec.js +++ b/spec/server/lib/sql-templates.spec.js @@ -2,8 +2,8 @@ const expect = require('chai').expect; const proxyquire = require('proxyquire'); const sinon = require('sinon'); -const Production = require('../../../server/models/production'); -const Theatre = require('../../../server/models/theatre'); +const Production = require('../../../dist/models/production'); +const Theatre = require('../../../dist/models/theatre'); const stubs = { format: { @@ -25,7 +25,7 @@ beforeEach(function () { }); -const subject = proxyquire('../../../server/lib/sql-templates', { +const subject = proxyquire('../../../dist/lib/sql-templates', { 'pg-format': stubs.format }); @@ -216,14 +216,14 @@ describe('SQL Templates module', () => { }); - describe('delete method', () => { + describe('deletion method', () => { context('production model', () => { - context('called within delete method', () => { + context('called within deletion method', () => { it('will return query that deletes given instance', () => { - const query = subject.delete(stubs.Production); + const query = subject.deletion(stubs.Production); expect(removeWhitespace(query)).to.eq(removeWhitespace(` DELETE FROM productions WHERE id = 'pgFormatValue' @@ -237,10 +237,10 @@ describe('SQL Templates module', () => { context('theatre model', () => { - context('called within delete method', () => { + context('called within deletion method', () => { it('will return query that deletes given instance', () => { - const query = subject.delete(stubs.Theatre); + const query = subject.deletion(stubs.Theatre); expect(removeWhitespace(query)).to.eq(removeWhitespace(` DELETE FROM theatres WHERE id = 'pgFormatValue' diff --git a/spec/server/lib/trim-strings.spec.js b/spec/server/lib/trim-strings.spec.js index 6963c8ae..a189b1ef 100644 --- a/spec/server/lib/trim-strings.spec.js +++ b/spec/server/lib/trim-strings.spec.js @@ -23,7 +23,7 @@ beforeEach(function () { }); const createSubject = (stubOverrides = {}) => - proxyquire('../../../server/lib/trim-strings', { + proxyquire('../../../dist/lib/trim-strings', { './prop-is-object': stubOverrides.propIsObject || stubs.propIsObject }); diff --git a/spec/server/lib/validate-string.spec.js b/spec/server/lib/validate-string.spec.js index a33ad720..af15b319 100644 --- a/spec/server/lib/validate-string.spec.js +++ b/spec/server/lib/validate-string.spec.js @@ -1,12 +1,12 @@ const expect = require('chai').expect; -const constants = require('../../../server/lib/constants'); +const constants = require('../../../dist/lib/constants'); const validLengthString = `${'a'.repeat(constants.STRING_MIN_LENGTH)}`; const subMinLengthString = `${'a'.repeat(constants.STRING_MIN_LENGTH - 1)}`; const surMaxLengthString = `${'a'.repeat(constants.STRING_MAX_LENGTH + 1)}`; -const subject = require('../../../server/lib/validate-string'); +const subject = require('../../../dist/lib/validate-string'); describe('Validate String module', () => { diff --git a/spec/server/lib/verify-error-presence.spec.js b/spec/server/lib/verify-error-presence.spec.js index 9c7fb2f3..c88a14d3 100644 --- a/spec/server/lib/verify-error-presence.spec.js +++ b/spec/server/lib/verify-error-presence.spec.js @@ -21,7 +21,7 @@ beforeEach(function () { }); const createSubject = (stubOverrides = {}) => - proxyquire('../../../server/lib/verify-error-presence', { + proxyquire('../../../dist/lib/verify-error-presence', { './prop-is-object': stubOverrides.propIsObject || stubs.propIsObject }); diff --git a/spec/server/models/production.spec.js b/spec/server/models/production.spec.js index 7613fed8..70f854df 100644 --- a/spec/server/models/production.spec.js +++ b/spec/server/models/production.spec.js @@ -51,8 +51,8 @@ beforeEach(function () { let instance; const createSubject = stubOverrides => - proxyquire('../../../server/models/production', { - '../../database/query': stubs.query, + proxyquire('../../../dist/models/production', { + '../database/query': stubs.query, '../lib/renew-top-level-values': stubs.renewTopLevelValues, '../lib/sql-templates': stubs.sqlTemplates, '../lib/trim-strings': stubs.trimStrings, diff --git a/spec/server/models/theatre.spec.js b/spec/server/models/theatre.spec.js index f0dc6739..50d7dac2 100644 --- a/spec/server/models/theatre.spec.js +++ b/spec/server/models/theatre.spec.js @@ -3,7 +3,7 @@ const proxyquire = require('proxyquire'); const sinon = require('sinon'); require('sinon-as-promised'); -const Production = require('../../../server/models/production'); +const Production = require('../../../dist/models/production'); const queryFixture = require('../../fixtures/query'); @@ -48,8 +48,8 @@ beforeEach(function () { let instance; const createSubject = stubOverrides => - proxyquire('../../../server/models/theatre', { - '../../database/query': stubOverrides.query || stubs.query, + proxyquire('../../../dist/models/theatre', { + '../database/query': stubOverrides.query || stubs.query, '../lib/renew-top-level-values': stubs.renewTopLevelValues, '../lib/sql-templates': stubs.sqlTemplates, '../lib/trim-strings': stubs.trimStrings,