Skip to content

Commit 496fb7b

Browse files
committed
feat(gen:endpoint): create models spec files
recreation of PR #1143 from @danmmx
1 parent 66ea123 commit 496fb7b

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

Diff for: src/test/get-expected-files.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function app(options) {
112112
]);
113113

114114
/* TypeScript */
115-
if (options.transpiler === 'ts') {
115+
if(options.transpiler === 'ts') {
116116
files = files.concat([
117117
'tsconfig.client.test.json',
118118
'tsconfig.client.json',
@@ -131,14 +131,14 @@ export function app(options) {
131131
}
132132

133133
/* Ui-Router */
134-
if (options.router === 'uirouter') {
134+
if(options.router === 'uirouter') {
135135
files = files.concat([
136136
'client/components/ui-router/ui-router.mock.' + script
137137
]);
138138
}
139139

140140
/* Ui-Bootstrap */
141-
if (options.uibootstrap) {
141+
if(options.uibootstrap) {
142142
files = files.concat([
143143
'client/components/modal/modal.' + markup,
144144
'client/components/modal/modal.' + stylesheet,
@@ -147,23 +147,24 @@ export function app(options) {
147147
}
148148

149149
/* Models - Mongoose or Sequelize */
150-
if (models) {
150+
if(models) {
151151
files = files.concat([
152152
'server/api/thing/thing.model.js',
153+
'server/api/thing/thing.model.spec.js',
153154
'server/api/thing/thing.events.js',
154155
'server/config/seed.js'
155156
]);
156157
}
157158

158159
/* Sequelize */
159-
if (options.odms.indexOf('sequelize') !== -1) {
160+
if(options.odms.indexOf('sequelize') !== -1) {
160161
files = files.concat([
161162
'server/sqldb/index.js'
162163
]);
163164
}
164165

165166
/* Authentication */
166-
if (options.auth) {
167+
if(options.auth) {
167168
files = files.concat([
168169
'client/app/account/index.' + script,
169170
'client/app/account/account.routes.' + script,
@@ -206,7 +207,7 @@ export function app(options) {
206207
]);
207208
}
208209

209-
if (options.oauth && options.oauth.length) {
210+
if(options.oauth && options.oauth.length) {
210211
/* OAuth (see oauthFiles function above) */
211212
options.oauth.forEach(function(type, i) {
212213
files = files.concat(oauthFiles(type.replace('Auth', '')));
@@ -224,7 +225,7 @@ export function app(options) {
224225
}
225226

226227
/* Socket.IO */
227-
if (options.socketio) {
228+
if(options.socketio) {
228229
files = files.concat([
229230
'client/components/socket/socket.service.' + script,
230231
'client/components/socket/socket.mock.' + script,
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
var app = require('../../app');
4+
var <%= classedName %> = require('./<%= basename %>.model');
5+
var <%= cameledName %>;
6+
var gen<%= classedName %> = function() {
7+
<%= cameledName %> = new <%= classedName %>({
8+
name: 'Fake <%= classedName %>',
9+
info: 'some info',
10+
active: true
11+
});
12+
return <%= cameledName %>;
13+
};
14+
15+
describe('<%= classedName %> Model', function() {
16+
before(function() {
17+
// Clear <%= basename %>s before testing
18+
return <%= classedName %>.find({}).removeAsync();
19+
});
20+
21+
beforeEach(function() {
22+
gen<%= classedName %>();
23+
});
24+
25+
afterEach(function() {
26+
return <%= classedName %>.find({}).removeAsync();
27+
});
28+
29+
it('should begin with no <%= basename %>s', function() {
30+
return <%= classedName %>.findAsync({})
31+
.should.eventually.have.length(0);
32+
});
33+
34+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
var app = require('../../app');
4+
var <%= classedName %> = require('../../sqldb').<%= classedName %>;
5+
var <%= cameledName %>;
6+
var gen<%= classedName %> = function() {
7+
<%= cameledName %> = <%= classedName %>.build({
8+
name: 'Fake <%= classedName %>',
9+
info: 'some info',
10+
active: true
11+
});
12+
return <%= cameledName %>;
13+
};
14+
15+
describe('<%= classedName %> Model', function() {
16+
before(function() {
17+
// Sync and clear <%= basename %>s before testing
18+
return <%= classedName %>.sync().then(function() {
19+
return <%= classedName %>.destroy({ where: {} });
20+
});
21+
});
22+
23+
beforeEach(function() {
24+
gen<%= classedName %>();
25+
});
26+
27+
afterEach(function() {
28+
return <%= classedName %>.destroy({ where: {} });
29+
});
30+
31+
it('should begin with no <%= basename %>s', function() {
32+
return <%= classedName %>.findAll()
33+
.should.eventually.have.length(0);
34+
});
35+
});

0 commit comments

Comments
 (0)