@@ -6,6 +6,9 @@ describe('helpers', function () {
6
6
var testApp = loopback ( ) ;
7
7
var db = testApp . dataSource ( 'db' , { connector : loopback . Memory } ) ;
8
8
var testModel = testApp . model ( 'xxx-test-model' , { dataSource : 'db' } ) ;
9
+ testApp . model ( loopback . User , { dataSource : 'db' } ) ;
10
+ testApp . model ( loopback . Role , { dataSource : 'db' } ) ;
11
+ testApp . model ( loopback . RoleMapping , { dataSource : 'db' } ) ;
9
12
10
13
testApp . use ( loopback . rest ( ) ) ;
11
14
helpers . beforeEach . withApp ( testApp ) ;
@@ -109,4 +112,50 @@ describe('helpers', function () {
109
112
} ) ;
110
113
} ) ;
111
114
} ) ;
115
+
116
+ describe ( 'givenUserWithRole' , function ( ) {
117
+ describe ( 'role as string' , function ( ) {
118
+ helpers . beforeEach . givenUserWithRole (
119
+ { id :
1 , email :
"[email protected] " , password :
"abc" } ,
120
+ "testRole" ) ;
121
+ it ( "should create a user instance with default userModel with the given role" , function ( ) {
122
+ assert . equal ( this [ 'User' ] . id , 1 ) ;
123
+ assert . equal ( this . userRole . id , 1 ) ;
124
+ assert . equal ( this . userRole . name , "testRole" ) ;
125
+ assert ( this . userRoleMapping ) ;
126
+ } ) ;
127
+ } )
128
+ describe ( 'role as object' , function ( ) {
129
+ helpers . beforeEach . givenUserWithRole (
130
+ { id :
1 , email :
"[email protected] " , password :
"abc" } ,
131
+ { id : 2 , name : "testRole" } ) ;
132
+ it ( "should create a user instance with default userModel with the given role" , function ( ) {
133
+ assert . equal ( this [ 'User' ] . id , 1 ) ;
134
+ assert . equal ( this . userRole . id , 2 ) ;
135
+ assert . equal ( this . userRole . name , "testRole" ) ;
136
+ assert ( this . userRoleMapping ) ;
137
+ } ) ;
138
+ } )
139
+ } ) ;
140
+ describe ( 'withUserModel' , function ( ) {
141
+ helpers . beforeEach . withUserModel ( 'xxx-test-model' ) ;
142
+ it ( "should set the user model name" , function ( ) {
143
+ assert . equal ( this . userModel , 'xxx-test-model' ) ;
144
+ } ) ;
145
+ describe ( 'givenUser' , function ( ) {
146
+ helpers . beforeEach . givenUser ( ) ;
147
+ it ( "should create a new instance of specified User model" , function ( ) {
148
+ assert ( this [ this . userModel ] ) ;
149
+ } ) ;
150
+ } ) ;
151
+ describe ( 'givenUserWithRole' , function ( ) {
152
+ helpers . beforeEach . givenUserWithRole ( { id : 1 } , { id : 2 , name : "testRole" } ) ;
153
+ it ( "should create a user instance (of specified User model) with the given role" , function ( ) {
154
+ assert . equal ( this [ this . userModel ] . id , 1 ) ;
155
+ assert . equal ( this . userRole . id , 2 ) ;
156
+ assert . equal ( this . userRole . name , "testRole" ) ;
157
+ assert ( this . userRoleMapping ) ;
158
+ } ) ;
159
+ } ) ;
160
+ } ) ;
112
161
} ) ;
0 commit comments