gcauth.guard.service - added test case 65/59165/1
authorArundathi Patil <arundpil@in.ibm.com>
Mon, 6 Aug 2018 11:09:01 +0000 (16:39 +0530)
committerIBM602-PC0F1E3C\Arundathi <arundpil@in.ibm.com>
Mon, 6 Aug 2018 11:09:15 +0000 (16:39 +0530)
Added test case to cover canActivate method when referenceObject is not
defined.

Issue-ID: APPC-1064
Change-Id: I19d08cf1e0b6426e52d1db48be89ed8e76864560
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts

index dc1d253..440993d 100644 (file)
@@ -27,7 +27,7 @@ import {CommonModule} from '@angular/common';
 import 'rxjs/Rx';
 import 'rxjs/add/observable/throw';
 import 'rxjs/add/operator/map';
-import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
+import { NgbModule, NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { GCAuthGuardService } from './gcauth-guard.service';
 import {MappingEditorService} from '../../shared/services/mapping-editor.service';
 import { promise } from 'protractor';
@@ -50,7 +50,7 @@ describe('LogginGuard', () => {
         loggedInGuard = TestBed.get(GCAuthGuardService);
     });
 
-    it('be able to hit route when user is logged in', inject([GCAuthGuardService, MappingEditorService], (service: GCAuthGuardService, mapService: MappingEditorService) => {
+    it('be able to return true when referenceNameObjects is defined', inject([GCAuthGuardService, MappingEditorService], (service: GCAuthGuardService, mapService: MappingEditorService) => {
         localStorage['userId'] = 'abc@xyz.com';
         mapService.referenceNameObjects = { data : 'data'};
         let route : ActivatedRouteSnapshot;
@@ -59,4 +59,15 @@ describe('LogginGuard', () => {
             expect(value).toBe(true);
         })
     }));
+
+    it('stop routing if referenceNameObjects is not defined', inject([GCAuthGuardService, MappingEditorService, NgbModal], (service: GCAuthGuardService, mapService: MappingEditorService, ngbModal: NgbModal) => {
+        localStorage['userId'] = 'abc@xyz.com';
+        mapService.referenceNameObjects = undefined;
+       let spy =  spyOn(NgbModal.prototype, 'open').and.returnValue(Promise.resolve(true));
+        let route : ActivatedRouteSnapshot;
+        let state: RouterStateSnapshot;
+        service.canActivate(route, state).then((value)=>{
+            expect(value).toBe(true);
+        })
+    }));
 });