Here is the function I have in my TypeScript file:
routeToIndividualPortal(sessionToken: string) {
let redirectUrl = this.relayState;
console.log("Pre-source-check Indivual URL : " + redirectUrl);
let url = "";
if(redirectUrl.includes(this.envSvc.environment.peakAppId)){
url = this.sessionTokenUrl + sessionToken + "&redirectUrl=" + this.relayState;
console.log("peak url : " + url);
}
else{
url = this.sessionTokenUrl + sessionToken + "&redirectUrl=" +this.individualLoginRouterUrl + "&requestedUrl=" + redirectUrl
console.log("C4 url : " + url);
}
console.log("window.location.href : " + url);
window.open(url);
}
And here is the test case that I have written, it is passing but only covering the else part and not the if part:
it('test routeToIndividualPortal', () => {
envSvc = new EnvironmentService(window);
envSvc.environment = new Environment();
envSvc.environment.peakAppId = 'RelayState=0oartebbbbs4KnvOK0h7';
let sessionToken = "randomstuffljbn";
let redirectUrl = "";
expect(component.relayState).toEqual(redirectUrl);
spyOn(window, 'open');
component.ngOnInit();
component.routeToIndividualPortal(sessionToken);
fixture.detectChanges();
expect(component.loginInvalid).toBeTruthy();
});
I am unsure of what I might be missing here, so any assistance in identifying where I went wrong would be greatly appreciated!