Skip to content

Commit

Permalink
feat(gen:endpoint): create models spec files
Browse files Browse the repository at this point in the history
recreation of PR #1143 from @danmmx
  • Loading branch information
Awk34 committed Dec 8, 2016
1 parent 579e773 commit b6a2474
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/test/get-expected-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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', '')));
Expand All @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions templates/endpoint/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 templates/endpoint/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);
});
});

0 comments on commit b6a2474

Please sign in to comment.