Skip to content

feat(gen:endpoint): create models spec files #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ module.exports = function (grunt) {
mochaTest: {
options: {
reporter: 'spec',
require: 'mocha.conf.js'
require: 'mocha.conf.js',
timeout: 5000 // set default mocha spec timeout
},
unit: {
src: ['server/**/*.spec.js']
Expand Down
6 changes: 3 additions & 3 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"passport-facebook": "latest",<% } %><% if (filters.twitterAuth) { %>
"passport-twitter": "latest",<% } %><% if (filters.googleAuth) { %>
"passport-google-oauth": "latest",<% } %><% if (filters.socketio) { %>
"socket.io": "^1.0.6",
"socket.io-client": "^1.0.6",
"socketio-jwt": "^3.0.0",<% } %>
"socket.io": "^1.3.5",
"socket.io-client": "^1.3.5",
"socketio-jwt": "^4.2.0",<% } %>
"serve-favicon": "~2.0.1"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion app/templates/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ module.exports = function(config) {

// testing framework to use (jasmine/mocha/qunit/...)<% if (filters.jasmine) { %>
frameworks: ['jasmine'],<% } if (filters.mocha) { %>
frameworks: ['mocha', 'chai', 'sinon-chai', 'chai-as-promised', 'chai-things'],<% } %>
frameworks: ['mocha', 'chai', 'sinon-chai', 'chai-as-promised', 'chai-things'],

client: {
mocha: {
timeout: 5000 // set default mocha spec timeout
}
},<% } %>

// list of files / patterns to load in the browser
files: [
Expand Down
8 changes: 3 additions & 5 deletions app/templates/server/config/socketio(socketio).js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function(socketio) {
//
// ex: DEBUG: "http*,socket.io:socket"

// We can authenticate socket.io users and access their token through socket.handshake.decoded_token
// We can authenticate socket.io users and access their token through socket.decoded_token
//
// 1. You will need to send the token in `client/components/socket/socket.service.js`
//
Expand All @@ -38,10 +38,8 @@ module.exports = function(socketio) {
// }));

socketio.on('connection', function(socket) {
socket.address =
socket.handshake.address !== null ?
socket.handshake.address.address + ':' + socket.handshake.address.port :
process.env.DOMAIN;
socket.address = socket.request.connection.remoteAddress +
':' + socket.request.connection.remotePort;

socket.connectedAt = new Date();

Expand Down
34 changes: 34 additions & 0 deletions endpoint/templates/basename.model.spec(mongooseModels).js
Original file line number Diff line number Diff line change
@@ -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);
});

});
35 changes: 35 additions & 0 deletions endpoint/templates/basename.model.spec(sequelizeModels).js
Original file line number Diff line number Diff line change
@@ -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);
});
});
1 change: 1 addition & 0 deletions test/test-file-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ describe('angular-fullstack generator', function () {
files = files.concat([
'server/api/thing/thing.model.js',
'server/api/thing/thing.events.js',
'server/api/thing/thing.model.spec.js',
'server/config/seed.js'
]);
}
Expand Down