File tree 5 files changed +84
-10
lines changed
5 files changed +84
-10
lines changed Original file line number Diff line number Diff line change @@ -473,9 +473,9 @@ Generator.prototype.serverFiles = function () {
473
473
this . template ( '../../templates/express/server.js' , 'server.js' ) ;
474
474
this . copy ( '../../templates/express/jshintrc' , 'lib/.jshintrc' ) ;
475
475
this . template ( '../../templates/express/controllers/api.js' , 'lib/controllers/api.js' ) ;
476
- this . template ( '../../templates/express/test/api/api.js' , 'test/server/api/api.js' ) ;
477
476
this . template ( '../../templates/express/controllers/index.js' , 'lib/controllers/index.js' ) ;
478
477
this . template ( '../../templates/express/routes.js' , 'lib/routes.js' ) ;
478
+ this . template ( '../../templates/express/test/thing/api.js' , 'test/server/thing/api.js' ) ;
479
479
480
480
this . template ( '../../templates/express/config/express.js' , 'lib/config/express.js' ) ;
481
481
this . template ( '../../templates/express/config/config.js' , 'lib/config/config.js' ) ;
@@ -520,4 +520,6 @@ Generator.prototype.mongoFiles = function () {
520
520
// controllers
521
521
this . template ( '../../templates/express/controllers/session.js' , 'lib/controllers/session.js' ) ;
522
522
this . template ( '../../templates/express/controllers/users.js' , 'lib/controllers/users.js' ) ;
523
+ // tests
524
+ this . template ( '../../templates/express/test/user/model.js' , 'test/server/user/model.js' ) ;
523
525
} ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ module.exports = function (grunt) {
65
65
mochaTest : {
66
66
files : [ 'test/server/{,*/}*.js' ] ,
67
67
tasks : [ 'mochaTest' ]
68
- } ,
68
+ } ,
69
69
jsTest : {
70
70
files : [ 'test/spec/{,*/}*.js' ] ,
71
71
tasks : [ 'newer:jshint:test' , 'karma' ]
@@ -428,12 +428,19 @@ module.exports = function (grunt) {
428
428
configFile : 'karma.conf.js' ,
429
429
singleRun : true
430
430
}
431
- } ,
432
- mochaTest: {
433
- options : {
434
- reporter : 'spec'
435
- } ,
436
- src : [ 'test/server/**/*.js' ]
431
+ } ,
432
+
433
+ mochaTest: {
434
+ options : {
435
+ reporter : 'spec'
436
+ } ,
437
+ src : [ 'test/server/**/*.js' ]
438
+ } ,
439
+
440
+ env: {
441
+ test : {
442
+ NODE_ENV : 'test'
443
+ }
437
444
}
438
445
} ) ;
439
446
@@ -476,7 +483,10 @@ module.exports = function (grunt) {
476
483
477
484
grunt.registerTask('test', function(target) {
478
485
if ( target === 'server' ) {
479
- return grunt . task . run ( [ 'mochaTest' ] ) ;
486
+ return grunt . task . run ( [
487
+ 'env:test' ,
488
+ 'mochaTest'
489
+ ] ) ;
480
490
}
481
491
482
492
if (target === 'client') {
@@ -489,6 +499,7 @@ module.exports = function (grunt) {
489
499
}
490
500
491
501
grunt.task.run([
502
+ 'env:test',
492
503
'mochaTest',
493
504
'clean:server',
494
505
'concurrent:test',
Original file line number Diff line number Diff line change 56
56
"karma-ng-html2js-preprocessor" : " ~0.1.0" ,
57
57
"grunt-mocha-test" : " ~0.8.1" ,
58
58
"supertest" : " ~0.8.2" ,
59
- "should" : " ~2.1.0"
59
+ "should" : " ~2.1.0" ,
60
+ "grunt-env" : " ~0.4.1"
60
61
},
61
62
"engines" : {
62
63
"node" : " >=0.10.0"
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var should = require ( 'should' ) ,
4
+ mongoose = require ( 'mongoose' ) ,
5
+ User = mongoose . model ( 'User' ) ;
6
+
7
+ var user ;
8
+
9
+ describe ( 'User Model' , function ( ) {
10
+ before ( function ( done ) {
11
+ user = new User ( {
12
+ provider : 'local' ,
13
+ name : 'Fake User' ,
14
+
15
+ password : 'password'
16
+ } ) ;
17
+
18
+ // Clear users before testing
19
+ User . remove ( ) . exec ( ) ;
20
+ done ( ) ;
21
+ } ) ;
22
+
23
+ afterEach ( function ( done ) {
24
+ User . remove ( ) . exec ( ) ;
25
+ done ( ) ;
26
+ } ) ;
27
+
28
+ it ( 'should begin with no users' , function ( done ) {
29
+ User . find ( { } , function ( err , users ) {
30
+ users . should . have . length ( 0 ) ;
31
+ done ( ) ;
32
+ } ) ;
33
+ } ) ;
34
+
35
+ it ( 'should fail when saving a duplicate user' , function ( done ) {
36
+ user . save ( ) ;
37
+ var userDup = new User ( user ) ;
38
+ userDup . save ( function ( err ) {
39
+ should . exist ( err ) ;
40
+ done ( ) ;
41
+ } ) ;
42
+ } ) ;
43
+
44
+ it ( 'should fail when saving without an email' , function ( done ) {
45
+ user . email = '' ;
46
+ user . save ( function ( err ) {
47
+ should . exist ( err ) ;
48
+ done ( ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ it ( "should authenticate user if password is valid" , function ( ) {
53
+ user . authenticate ( 'password' ) . should . be . true ;
54
+ } ) ;
55
+
56
+ it ( "should not authenticate user if password is invalid" , function ( ) {
57
+ user . authenticate ( 'blah' ) . should . not . be . true ;
58
+ } ) ;
59
+
60
+ } ) ;
You can’t perform that action at this time.
0 commit comments