diff --git a/src/test/get-expected-files.js b/src/test/get-expected-files.js index 70b4bfc9c..7edd9f4f4 100644 --- a/src/test/get-expected-files.js +++ b/src/test/get-expected-files.js @@ -112,7 +112,7 @@ export function app(options) { ]); /* TypeScript */ - if (options.transpiler === 'ts') { + if(options.transpiler === 'ts') { files = files.concat([ 'tsconfig.client.test.json', 'tsconfig.client.json', @@ -131,14 +131,14 @@ export function app(options) { } /* Ui-Router */ - if (options.router === 'uirouter') { + if(options.router === 'uirouter') { files = files.concat([ 'client/components/ui-router/ui-router.mock.' + script ]); } /* Ui-Bootstrap */ - if (options.uibootstrap) { + if(options.uibootstrap) { files = files.concat([ 'client/components/modal/modal.' + markup, 'client/components/modal/modal.' + stylesheet, @@ -147,23 +147,24 @@ export function app(options) { } /* Models - Mongoose or Sequelize */ - if (models) { + if(models) { files = files.concat([ 'server/api/thing/thing.model.js', + 'server/api/thing/thing.model.spec.js', 'server/api/thing/thing.events.js', 'server/config/seed.js' ]); } /* Sequelize */ - if (options.odms.indexOf('sequelize') !== -1) { + if(options.odms.indexOf('sequelize') !== -1) { files = files.concat([ 'server/sqldb/index.js' ]); } /* Authentication */ - if (options.auth) { + if(options.auth) { files = files.concat([ 'client/app/account/index.' + script, 'client/app/account/account.routes.' + script, @@ -206,7 +207,7 @@ export function app(options) { ]); } - if (options.oauth && options.oauth.length) { + if(options.oauth && options.oauth.length) { /* OAuth (see oauthFiles function above) */ options.oauth.forEach(function(type, i) { files = files.concat(oauthFiles(type.replace('Auth', ''))); @@ -224,7 +225,7 @@ export function app(options) { } /* Socket.IO */ - if (options.socketio) { + if(options.socketio) { files = files.concat([ 'client/components/socket/socket.service.' + script, 'client/components/socket/socket.mock.' + script, diff --git a/templates/endpoint/basename.model.spec(mongooseModels).js b/templates/endpoint/basename.model.spec(mongooseModels).js new file mode 100644 index 000000000..58fc61165 --- /dev/null +++ b/templates/endpoint/basename.model.spec(mongooseModels).js @@ -0,0 +1,34 @@ +'use strict'; + +var app = require('../../app'); +var <%= classedName %> = require('./<%= basename %>.model'); +var <%= cameledName %>; +var gen<%= classedName %> = function() { + <%= cameledName %> = new <%= classedName %>({ + name: 'Fake <%= classedName %>', + info: 'some info', + active: true + }); + return <%= cameledName %>; +}; + +describe('<%= classedName %> Model', function() { + before(function() { + // Clear <%= basename %>s before testing + return <%= classedName %>.find({}).removeAsync(); + }); + + beforeEach(function() { + gen<%= classedName %>(); + }); + + afterEach(function() { + return <%= classedName %>.find({}).removeAsync(); + }); + + it('should begin with no <%= basename %>s', function() { + return <%= classedName %>.findAsync({}) + .should.eventually.have.length(0); + }); + +}); diff --git a/templates/endpoint/basename.model.spec(sequelizeModels).js b/templates/endpoint/basename.model.spec(sequelizeModels).js new file mode 100644 index 000000000..43d2a27ad --- /dev/null +++ b/templates/endpoint/basename.model.spec(sequelizeModels).js @@ -0,0 +1,35 @@ +'use strict'; + +var app = require('../../app'); +var <%= classedName %> = require('../../sqldb').<%= classedName %>; +var <%= cameledName %>; +var gen<%= classedName %> = function() { + <%= cameledName %> = <%= classedName %>.build({ + name: 'Fake <%= classedName %>', + info: 'some info', + active: true + }); + return <%= cameledName %>; +}; + +describe('<%= classedName %> Model', function() { + before(function() { + // Sync and clear <%= basename %>s before testing + return <%= classedName %>.sync().then(function() { + return <%= classedName %>.destroy({ where: {} }); + }); + }); + + beforeEach(function() { + gen<%= classedName %>(); + }); + + afterEach(function() { + return <%= classedName %>.destroy({ where: {} }); + }); + + it('should begin with no <%= basename %>s', function() { + return <%= classedName %>.findAll() + .should.eventually.have.length(0); + }); +});