11var
22 should = require ( 'should' ) ,
33 Kuzzle = require ( '../../../src/Kuzzle' ) ,
4- Profile = require ( '../../../src/security/kuzzleProfile ' ) ,
4+ Profile = require ( '../../../src/security/Profile ' ) ,
55 Role = require ( '../../../src/security/kuzzleRole' ) ;
66
77describe ( 'Profile methods' , function ( ) {
88 var
99 kuzzle ,
10- kuzzleProfile ,
10+ profile ,
1111 result ,
1212 expectedQuery ,
1313 error = null ,
@@ -49,18 +49,18 @@ describe('Profile methods', function () {
4949 error = null ;
5050
5151 result = { result : { _id : 'myProfile' , _source : { policies : [ ] } } } ;
52- kuzzleProfile = new Profile ( kuzzle . security , result . result . _id , result . result . _source ) ;
52+ profile = new Profile ( kuzzle . security , result . result . _id , result . result . _source ) ;
5353 expectedQuery = {
5454 action : 'createOrReplaceProfile' ,
5555 controller : 'security'
5656 } ;
5757 } ) ;
5858
5959 it ( 'should throw an error if the profile has not roles parameter' , function ( done ) {
60- kuzzleProfile = new Profile ( kuzzle . security , result . result . _id , { some : 'content' } ) ;
60+ profile = new Profile ( kuzzle . security , result . result . _id , { some : 'content' } ) ;
6161
6262 should ( ( function ( ) {
63- kuzzleProfile . save ( ) ;
63+ profile . save ( ) ;
6464 } ) ) . throw ( Error ) ;
6565
6666 done ( ) ;
@@ -70,7 +70,7 @@ describe('Profile methods', function () {
7070 expectedQuery . body = result . result . _source ;
7171 expectedQuery . _id = result . result . _id ;
7272
73- should ( kuzzleProfile . save ( function ( err , res ) {
73+ should ( profile . save ( function ( err , res ) {
7474 should ( err ) . be . null ( ) ;
7575 should ( res ) . be . instanceof ( Profile ) ;
7676 done ( ) ;
@@ -83,7 +83,7 @@ describe('Profile methods', function () {
8383 error = 'foobar' ;
8484 this . timeout ( 50 ) ;
8585
86- kuzzleProfile . save ( function ( err , res ) {
86+ profile . save ( function ( err , res ) {
8787 should ( err ) . be . exactly ( 'foobar' ) ;
8888 should ( res ) . be . undefined ( ) ;
8989 done ( ) ;
@@ -109,7 +109,7 @@ describe('Profile methods', function () {
109109 expectedQuery . body = { 'foo' : 'bar' } ;
110110 expectedQuery . _id = result . result . _id ;
111111
112- should ( kuzzleProfile . update ( { 'foo' : 'bar' } , function ( err , res ) {
112+ should ( profile . update ( { 'foo' : 'bar' } , function ( err , res ) {
113113 should ( err ) . be . null ( ) ;
114114 should ( res ) . be . instanceof ( Profile ) ;
115115 done ( ) ;
@@ -123,7 +123,7 @@ describe('Profile methods', function () {
123123 error = 'foobar' ;
124124 this . timeout ( 50 ) ;
125125
126- kuzzleProfile . update ( { 'foo' : 'bar' } , function ( err , res ) {
126+ profile . update ( { 'foo' : 'bar' } , function ( err , res ) {
127127 should ( err ) . be . exactly ( 'foobar' ) ;
128128 should ( res ) . be . undefined ( ) ;
129129 done ( ) ;
@@ -137,7 +137,7 @@ describe('Profile methods', function () {
137137 this . timeout ( 50 ) ;
138138
139139 try {
140- kuzzleProfile . update ( ) ;
140+ profile . update ( ) ;
141141 }
142142 catch ( e ) {
143143 should ( e ) . be . instanceOf ( Error ) ;
@@ -149,86 +149,86 @@ describe('Profile methods', function () {
149149 describe ( '#addPolicy' , function ( ) {
150150 beforeEach ( function ( ) {
151151 kuzzle = new Kuzzle ( 'http://localhost:7512' ) ;
152- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { policies : [ { roleId :'role1' } ] } ) ;
152+ profile = new Profile ( kuzzle . security , 'myProfile' , { policies : [ { roleId :'role1' } ] } ) ;
153153 } ) ;
154154
155155 it ( 'should throw an error if the policy parameter is not an object' , function ( done ) {
156156 should ( ( function ( ) {
157- kuzzleProfile . addPolicy ( null ) ;
157+ profile . addPolicy ( null ) ;
158158 } ) ) . throw ( Error ) ;
159159
160160 done ( ) ;
161161 } ) ;
162162
163163 it ( 'should throw an error if the policy.roleId parameter is not a string' , function ( done ) {
164164 should ( ( function ( ) {
165- kuzzleProfile . addPolicy ( { roleId : null } ) ;
165+ profile . addPolicy ( { roleId : null } ) ;
166166 } ) ) . throw ( Error ) ;
167167
168168 done ( ) ;
169169 } ) ;
170170
171171 it ( 'should add the right policy in policies list' , function ( done ) {
172- kuzzleProfile . addPolicy ( { roleId : 'role2' } ) ;
173- should ( kuzzleProfile . content . policies ) . be . an . Array ( ) . match ( [ { roleId : 'role1' } , { roleId : 'role2' } ] ) ;
174- should ( kuzzleProfile . content . policies . length ) . be . exactly ( 2 ) ;
172+ profile . addPolicy ( { roleId : 'role2' } ) ;
173+ should ( profile . content . policies ) . be . an . Array ( ) . match ( [ { roleId : 'role1' } , { roleId : 'role2' } ] ) ;
174+ should ( profile . content . policies . length ) . be . exactly ( 2 ) ;
175175 done ( ) ;
176176 } ) ;
177177
178178 it ( 'should initialize policies with array if no policy was set before' , function ( done ) {
179- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' } ) ;
179+ profile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' } ) ;
180180
181- kuzzleProfile . addPolicy ( { roleId : 'role' } ) ;
182- should ( kuzzleProfile . content . policies ) . be . an . Array ( ) ;
183- should ( kuzzleProfile . content . policies . length ) . be . exactly ( 1 ) ;
181+ profile . addPolicy ( { roleId : 'role' } ) ;
182+ should ( profile . content . policies ) . be . an . Array ( ) ;
183+ should ( profile . content . policies . length ) . be . exactly ( 1 ) ;
184184 done ( ) ;
185185 } ) ;
186186 } ) ;
187187
188188 describe ( '#setPolicies' , function ( ) {
189189 beforeEach ( function ( ) {
190190 kuzzle = new Kuzzle ( 'http://localhost:7512' ) ;
191- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { policies : [ { roleId :'role1' } ] } ) ;
191+ profile = new Profile ( kuzzle . security , 'myProfile' , { policies : [ { roleId :'role1' } ] } ) ;
192192 } ) ;
193193
194194 it ( 'should throw an error if the policies parameter is null' , function ( done ) {
195195 should ( ( function ( ) {
196- kuzzleProfile . setPolicies ( null ) ;
196+ profile . setPolicies ( null ) ;
197197 } ) ) . throw ( Error ) ;
198198
199199 done ( ) ;
200200 } ) ;
201201
202202 it ( 'should throw an error if the role parameter is not a array of objects' , function ( done ) {
203203 should ( ( function ( ) {
204- kuzzleProfile . setPolicies ( [ 1 , 2 , 3 ] ) ;
204+ profile . setPolicies ( [ 1 , 2 , 3 ] ) ;
205205 } ) ) . throw ( Error ) ;
206206
207207 done ( ) ;
208208 } ) ;
209209
210210 it ( 'should add the policy in policies list' , function ( done ) {
211- kuzzleProfile . setPolicies ( [ { roleId :'role2' } ] ) ;
212- should ( kuzzleProfile . content . policies ) . be . an . Array ( ) . match ( [ { roleId :'role2' } ] ) ;
211+ profile . setPolicies ( [ { roleId :'role2' } ] ) ;
212+ should ( profile . content . policies ) . be . an . Array ( ) . match ( [ { roleId :'role2' } ] ) ;
213213 done ( ) ;
214214 } ) ;
215215
216216 it ( 'should add the Role in roles list' , function ( done ) {
217- kuzzleProfile . setPolicies ( [ { roleId :'role1' } , { roleId :'role2' } ] ) ;
218- should ( kuzzleProfile . content . policies ) . be . an . Array ( ) ;
219- should ( kuzzleProfile . content . policies . length ) . be . exactly ( 2 ) ;
217+ profile . setPolicies ( [ { roleId :'role1' } , { roleId :'role2' } ] ) ;
218+ should ( profile . content . policies ) . be . an . Array ( ) ;
219+ should ( profile . content . policies . length ) . be . exactly ( 2 ) ;
220220 done ( ) ;
221221 } ) ;
222222 } ) ;
223223
224224 describe ( '#serialize' , function ( ) {
225225 beforeEach ( function ( ) {
226226 kuzzle = new Kuzzle ( 'http://localhost:7512' ) ;
227- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , policies : [ { roleId :'role1' } ] } ) ;
227+ profile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , policies : [ { roleId :'role1' } ] } ) ;
228228 } ) ;
229229
230230 it ( 'should serialize with correct attributes' , function ( done ) {
231- var serialized = kuzzleProfile . serialize ( ) ;
231+ var serialized = profile . serialize ( ) ;
232232
233233 should ( serialized . _id ) . be . exactly ( 'myProfile' ) ;
234234 should ( serialized . body ) . be . match ( { some : 'content' , policies : [ { roleId :'role1' } ] } ) ;
@@ -239,9 +239,9 @@ describe('Profile methods', function () {
239239 var
240240 serialized ;
241241
242- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' } ) ;
242+ profile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' } ) ;
243243
244- serialized = kuzzleProfile . serialize ( ) ;
244+ serialized = profile . serialize ( ) ;
245245
246246 should ( serialized . _id ) . be . exactly ( 'myProfile' ) ;
247247 should . exist ( serialized . body . some ) ;
@@ -257,7 +257,7 @@ describe('Profile methods', function () {
257257 error = null ;
258258
259259 result = { result : { _id : 'myProfile' } } ;
260- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , roles : [ { roleId :'role1' } ] } ) ;
260+ profile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , roles : [ { roleId :'role1' } ] } ) ;
261261 expectedQuery = {
262262 action : 'deleteProfile' ,
263263 controller : 'security'
@@ -268,7 +268,7 @@ describe('Profile methods', function () {
268268 expectedQuery . body = result . result . _source ;
269269 expectedQuery . _id = result . result . _id ;
270270
271- should ( kuzzleProfile . delete ( function ( err , res ) {
271+ should ( profile . delete ( function ( err , res ) {
272272 should ( err ) . be . null ( ) ;
273273 should ( res ) . be . exactly ( result . result . _id ) ;
274274 done ( ) ;
@@ -281,7 +281,7 @@ describe('Profile methods', function () {
281281
282282 error = 'foobar' ;
283283
284- kuzzleProfile . delete ( function ( err , res ) {
284+ profile . delete ( function ( err , res ) {
285285 should ( err ) . be . exactly ( 'foobar' ) ;
286286 should ( res ) . be . undefined ( ) ;
287287 done ( ) ;
@@ -294,8 +294,8 @@ describe('Profile methods', function () {
294294 var policies = [ { roleId :'role1' } , { roleId :'role2' } , { roleId :'role3' } ] ;
295295
296296 kuzzle = new Kuzzle ( 'http://localhost:7512' ) ;
297- kuzzleProfile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , policies : policies } ) ;
298- should ( kuzzleProfile . getPolicies ( ) ) . be . eql ( policies ) ;
297+ profile = new Profile ( kuzzle . security , 'myProfile' , { some : 'content' , policies : policies } ) ;
298+ should ( profile . getPolicies ( ) ) . be . eql ( policies ) ;
299299 } ) ;
300300 } ) ;
301301} ) ;
0 commit comments