@@ -22,13 +22,13 @@ describe('Helper Service', function() {
22
22
sinon . spy ( fakeState , "go" ) ;
23
23
24
24
beforeEach ( function ( ) {
25
- module ( 'tc.services ' , function ( $provide ) {
25
+ module ( 'topcoder ' , function ( $provide ) {
26
26
$provide . value ( '$window' , fakeWindow ) ;
27
27
$provide . value ( '$state' , fakeState ) ;
28
28
$provide . value ( '$location' , fakeLocation ) ;
29
29
} ) ;
30
30
31
- bard . inject ( this , 'Helpers' , '$state' , '$location' , '$window' ) ;
31
+ bard . inject ( this , 'Helpers' , '$rootScope' , '$ state', '$location' , '$window' , '$httpBackend ') ;
32
32
} ) ;
33
33
34
34
describe ( "isEmail()" , function ( ) {
@@ -310,5 +310,105 @@ describe('Helper Service', function() {
310
310
expect ( questions . q3 . reviewItemId ) . to . exist . to . equal ( 'a3' ) ;
311
311
expect ( questions . q3 . comment ) . to . exist . to . equal ( 'good' ) ;
312
312
} ) ;
313
+
314
+ it ( "should compile review items for first time creation " , function ( ) {
315
+ var questions = {
316
+ '1' : { id : '1' , questionTypeId : 5 , guideline : 'some guideline' } ,
317
+ '2' : { id : '2' , questionTypeId : 5 , guideline : 'some guideline\nsecond line' } ,
318
+ '3' : { id : '3' , questionTypeId : 5 , guideline : 'some guideline\nsecond line\nthird line' }
319
+ } ;
320
+ var answers = [
321
+ { id : 'a1' , scorecardQuestionId : '1' , answer : 3 , comments :[ { content : 'perfect' } ] } ,
322
+ { id : 'a2' , scorecardQuestionId : '2' , answer : 1 , comments :[ ] } ,
323
+ { id : 'a3' , scorecardQuestionId : '3' , answer : 2 , comments :[ { content : 'good' } ] }
324
+ ] ;
325
+ // assumes parseAnswers to be working as expected
326
+ Helpers . parseAnswers ( questions , answers ) ;
327
+
328
+ var review = { id : 'rev1' , resourceId : 'res1' , uploadId : 'u1' } ;
329
+ var reviewItems = Helpers . compileReviewItems ( questions , review , false ) ;
330
+ expect ( reviewItems ) . to . exist . to . have . length ( 3 ) ;
331
+ expect ( reviewItems [ 0 ] . reviewId ) . to . exist . to . equal ( review . id ) ;
332
+ expect ( reviewItems [ 0 ] . uploadId ) . to . exist . to . equal ( review . uploadId ) ;
333
+ // expect(reviewItems[0].id).to.exist.to.equal(answers[0].id);
334
+ expect ( reviewItems [ 0 ] . answer ) . to . exist . to . equal ( answers [ 0 ] . answer . toString ( ) ) ;
335
+ expect ( reviewItems [ 0 ] . scorecardQuestionId ) . to . exist . to . equal ( parseInt ( answers [ 0 ] . scorecardQuestionId ) ) ;
336
+ expect ( reviewItems [ 0 ] . comments ) . to . exist . to . have . length ( answers [ 0 ] . comments . length ) ;
337
+ } ) ;
338
+
339
+ it ( "should compile review items for updating existing review items " , function ( ) {
340
+ var questions = {
341
+ '1' : { id : '1' , questionTypeId : 5 , guideline : 'some guideline' , reviewItemId : 'revItem1' } ,
342
+ '2' : { id : '2' , questionTypeId : 5 , guideline : 'some guideline\nsecond line' , reviewItemId : 'revItem2' } ,
343
+ '3' : { id : '3' , questionTypeId : 5 , guideline : 'some guideline\nsecond line\nthird line' , reviewItemId : 'revItem3' }
344
+ } ;
345
+ var answers = [
346
+ { id : 'a1' , scorecardQuestionId : '1' , answer : 3 , comments :[ { content : 'perfect' } ] } ,
347
+ { id : 'a2' , scorecardQuestionId : '2' , answer : 1 , comments :[ ] } ,
348
+ { id : 'a3' , scorecardQuestionId : '3' , answer : 2 , comments :[ { content : 'good' } ] }
349
+ ] ;
350
+ // assumes parseAnswers to be working as expected
351
+ Helpers . parseAnswers ( questions , answers ) ;
352
+
353
+ var review = { id : 'rev1' , resourceId : 'res1' , uploadId : 'u1' } ;
354
+ var reviewItems = Helpers . compileReviewItems ( questions , review , true ) ;
355
+ expect ( reviewItems ) . to . exist . to . have . length ( 3 ) ;
356
+ expect ( reviewItems [ 0 ] . uploadId ) . to . exist . to . equal ( review . uploadId ) ;
357
+ expect ( reviewItems [ 0 ] . id ) . to . exist . to . equal ( answers [ 0 ] . id ) ;
358
+ expect ( reviewItems [ 0 ] . answer ) . to . exist . to . equal ( answers [ 0 ] . answer . toString ( ) ) ;
359
+ expect ( reviewItems [ 0 ] . scorecardQuestionId ) . to . exist . to . equal ( parseInt ( answers [ 0 ] . scorecardQuestionId ) ) ;
360
+ expect ( reviewItems [ 0 ] . comments ) . to . exist . to . have . length ( answers [ 0 ] . comments . length ) ;
361
+ } ) ;
362
+ } ) ;
363
+
364
+ describe ( "npad " , function ( ) {
365
+ it ( "should pad string with 0 " , function ( ) {
366
+ var padded = Helpers . npad ( "123" , 5 ) ;
367
+ expect ( padded ) . to . exist . to . equal ( '00123' ) ;
368
+ } ) ;
369
+
370
+ it ( "should pad number with 0 " , function ( ) {
371
+ var padded = Helpers . npad ( 123 , 5 ) ;
372
+ expect ( padded ) . to . exist . to . equal ( '00123' ) ;
373
+ } ) ;
374
+
375
+ it ( "should not pad string with 0 " , function ( ) {
376
+ var padded = Helpers . npad ( "12345" , 5 ) ;
377
+ expect ( padded ) . to . exist . to . equal ( '12345' ) ;
378
+ } ) ;
379
+ } ) ;
380
+
381
+ describe ( "setupLoginEventMetrics " , function ( ) {
382
+ it ( "should add object with identify key " , function ( ) {
383
+ $window . _kmq = [ ] ;
384
+ Helpers . setupLoginEventMetrics ( 'mockuser' ) ;
385
+ expect ( $window . _kmq ) . to . have . length ( 1 ) ;
386
+ expect ( $window . _kmq [ 0 ] [ 0 ] ) . to . exist . to . equal ( 'identify' ) ;
387
+ expect ( $window . _kmq [ 0 ] [ 1 ] ) . to . exist . to . equal ( 'mockuser' ) ;
388
+ } ) ;
389
+ } ) ;
390
+
391
+ xdescribe ( "getCountyObjFromIP " , function ( ) {
392
+ it ( "should get valid country object " , function ( ) {
393
+ var mockLocation = {
394
+ "ip" : "123.63.151.213" ,
395
+ "hostname" : "No Hostname" ,
396
+ "city" : "New Delhi" ,
397
+ "region" : "National Capital Territory of Delhi" ,
398
+ "country" : "IN" ,
399
+ "loc" : "28.6000,77.2000" ,
400
+ "org" : "Mock Organization"
401
+ } ;
402
+
403
+ $httpBackend
404
+ . when ( 'GET' , 'http://ipinfo.io' )
405
+ . respond ( 200 , mockLocation ) ;
406
+
407
+ $rootScope . $apply ( ) ;
408
+ console . log ( Helpers . getCountyObjFromIP ( ) . then ( function ( data ) {
409
+ console . log ( data ) ;
410
+ } ) ) ;
411
+ $rootScope . $apply ( ) ;
412
+ } ) ;
313
413
} ) ;
314
414
} ) ;
0 commit comments