This repository was archived by the owner on Aug 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ var mongoose = require('mongoose'),
15
15
var UserSchema = new Schema ( {
16
16
name : String ,
17
17
email : String ,
18
- username : String ,
18
+ username : { type : String , unique : true } ,
19
19
provider : String ,
20
20
hashed_password : String ,
21
21
facebook : { } ,
Original file line number Diff line number Diff line change @@ -52,7 +52,14 @@ describe('<Unit Test>', function() {
52
52
} ) ;
53
53
54
54
afterEach ( function ( done ) {
55
+ Article . remove ( { } ) ;
56
+ User . remove ( { } ) ;
57
+ done ( ) ;
58
+ } ) ;
59
+ after ( function ( done ) {
60
+ Article . remove ( ) . exec ( ) ;
61
+ User . remove ( ) . exec ( ) ;
55
62
done ( ) ;
56
63
} ) ;
57
64
} ) ;
58
- } ) ;
65
+ } ) ;
Original file line number Diff line number Diff line change @@ -19,15 +19,33 @@ describe('<Unit Test>', function() {
19
19
username : 'user' ,
20
20
password : 'password'
21
21
} ) ;
22
+ user2 = new User ( {
23
+ name : 'Full name' ,
24
+ email : 'test@test.com' ,
25
+ username : 'user' ,
26
+ password : 'password'
27
+ } ) ;
22
28
23
29
done ( ) ;
24
30
} ) ;
25
31
26
32
describe ( 'Method Save' , function ( ) {
33
+ it ( 'should begin with no users' , function ( done ) {
34
+ User . find ( { } , function ( err , users ) {
35
+ users . should . have . length ( 0 ) ;
36
+ done ( ) ;
37
+ } ) ;
38
+ } ) ;
39
+
27
40
it ( 'should be able to save whithout problems' , function ( done ) {
28
- return user . save ( function ( err ) {
29
- should . not . exist ( err ) ;
30
- done ( ) ;
41
+ user . save ( done ) ;
42
+ } ) ;
43
+
44
+ it ( 'should fail to save an existing user again' , function ( done ) {
45
+ user . save ( ) ;
46
+ return user2 . save ( function ( err ) {
47
+ should . exist ( err ) ;
48
+ done ( ) ;
31
49
} ) ;
32
50
} ) ;
33
51
@@ -41,7 +59,8 @@ describe('<Unit Test>', function() {
41
59
} ) ;
42
60
43
61
after ( function ( done ) {
62
+ User . remove ( ) . exec ( ) ;
44
63
done ( ) ;
45
64
} ) ;
46
65
} ) ;
47
- } ) ;
66
+ } ) ;
You can’t perform that action at this time.
0 commit comments