diff --git a/src/app/login/login-home/login-home.component.spec.ts b/src/app/login/login-home/login-home.component.spec.ts index 793a132cef1..23c179cd1c8 100644 --- a/src/app/login/login-home/login-home.component.spec.ts +++ b/src/app/login/login-home/login-home.component.spec.ts @@ -14,7 +14,7 @@ export class MockUserService { return false; } getRedirectUrl(): string { - return ''; + return '/path/to/redirect'; } } @@ -30,13 +30,16 @@ export class MockConfigService { observer.complete(); }); } + getContextPath(): string { + return '/wise'; + } getRecaptchaPublicKey(): string { return ''; } } +let component: LoginHomeComponent; describe('LoginHomeComponent', () => { - let component: LoginHomeComponent; let fixture: ComponentFixture; beforeEach( waitForAsync(() => { @@ -57,8 +60,15 @@ describe('LoginHomeComponent', () => { component = fixture.componentInstance; fixture.detectChanges(); }); + getRedirectUrl(); +}); - it('should create', () => { - expect(component).toBeTruthy(); +function getRedirectUrl() { + describe('getRedirectUrl()', () => { + it('should add redirectUrl to Google login url', () => { + expect(component.getRedirectUrl('google')).toEqual( + '/wise/api/google-login?redirectUrl=/path/to/redirect' + ); + }); }); -}); +} diff --git a/src/app/login/login-home/login-home.component.ts b/src/app/login/login-home/login-home.component.ts index 84eb31d297f..ef9ff6c4839 100644 --- a/src/app/login/login-home/login-home.component.ts +++ b/src/app/login/login-home/login-home.component.ts @@ -113,13 +113,17 @@ export class LoginHomeComponent implements OnInit { getRedirectUrl(social: string): string { let redirectUrl = ''; if (social === 'google') { - redirectUrl = `${this.configService.getContextPath()}/api/google-login`; + redirectUrl = `${this.configService.getContextPath()}/api/google-login?redirectUrl=${this.userService.getRedirectUrl()}`; } else { redirectUrl = this.userService.getRedirectUrl(); } if (this.accessCode !== '') { - redirectUrl = `${redirectUrl}?accessCode=${this.accessCode}`; + redirectUrl = this.appendAccessCodeParameter(redirectUrl); } return redirectUrl; } + + private appendAccessCodeParameter(url: string): string { + return `${url}${url.includes('?') ? '&' : '?'}accessCode=${this.accessCode}`; + } }