Modified redirectToPreviousUrl to use the standalone page parameter if no redirect url is found in the store.

Removed unused import that was causing merge conflict.

Once again try to fix merge conflict.

Added routeService to server module providers.

Changed order of providers.

Minor change to ServerAuthService to make method signature consistent with AuthService.

Try adding RouteService to browser-app module to see if that fixes travis build.

One more try at getting the CI build to work.

Removed change to browser module.
This commit is contained in:
Michael W Spalti
2019-09-06 12:18:28 -07:00
parent 0935bd4afd
commit d9fb68dce9
5 changed files with 34 additions and 44 deletions

View File

@@ -86,8 +86,6 @@ describe('AuthService test', () => {
], ],
}); });
authService = TestBed.get(AuthService); authService = TestBed.get(AuthService);
routeServiceMock = TestBed.get(RouteService);
spyOn(authService, 'setRedirectUrl');
}); });
it('should return the authentication status object when user credentials are correct', () => { it('should return the authentication status object when user credentials are correct', () => {
@@ -130,31 +128,6 @@ describe('AuthService test', () => {
expect(authService.logout.bind(null)).toThrow(); expect(authService.logout.bind(null)).toThrow();
}); });
it ('should dispatch authentication', () => {
authService.doAuthentication(true, '', '');
expect(mockStore.dispatch).toHaveBeenCalled();
});
it ('should set redirect url to previous page', () => {
spyOn(routeServiceMock, 'getHistory').and.callThrough();
authService.doAuthentication(true, '', '');
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(authService.setRedirectUrl).toHaveBeenCalledWith('/collection/123');
});
it ('should set redirect url to current page', () => {
spyOn(routeServiceMock, 'getHistory').and.callThrough();
authService.doAuthentication(false, '', '');
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(authService.setRedirectUrl).toHaveBeenCalledWith('/home');
});
it ('should not set redirect url to /login', () => {
spyOn(routeServiceMock, 'getHistory').and.returnValue(of(['/login', '/login']));
authService.doAuthentication(true, '', '');
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(authService.setRedirectUrl).not.toHaveBeenCalled();
});
}); });
describe('', () => { describe('', () => {
@@ -247,9 +220,12 @@ describe('AuthService test', () => {
}); });
authService = new AuthService({}, window, undefined, authReqService, router, routeService, cookieService, store, rdbService); authService = new AuthService({}, window, undefined, authReqService, router, routeService, cookieService, store, rdbService);
storage = (authService as any).storage; storage = (authService as any).storage;
routeServiceMock = TestBed.get(RouteService);
routerStub = TestBed.get(Router);
spyOn(storage, 'get'); spyOn(storage, 'get');
spyOn(storage, 'remove'); spyOn(storage, 'remove');
spyOn(storage, 'set'); spyOn(storage, 'set');
})); }));
it('should throw false when token is not valid', () => { it('should throw false when token is not valid', () => {
@@ -271,5 +247,32 @@ describe('AuthService test', () => {
expect(storage.remove).toHaveBeenCalled(); expect(storage.remove).toHaveBeenCalled();
}); });
it ('should set redirect url to previous page', () => {
spyOn(routeServiceMock, 'getHistory').and.callThrough();
authService.redirectToPreviousUrl(true);
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(routerStub.navigate).toHaveBeenCalledWith(['/collection/123']);
});
it ('should set redirect url to current page', () => {
spyOn(routeServiceMock, 'getHistory').and.callThrough();
authService.redirectToPreviousUrl(false);
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(routerStub.navigate).toHaveBeenCalledWith(['/home']);
});
it ('should redirect to / and not to /login', () => {
spyOn(routeServiceMock, 'getHistory').and.returnValue(of(['/login', '/login']));
authService.redirectToPreviousUrl(true);
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(routerStub.navigate).toHaveBeenCalledWith(['/']);
});
it ('should redirect to / when no redirect url is found', () => {
spyOn(routeServiceMock, 'getHistory').and.returnValue(of(['']));
authService.redirectToPreviousUrl(true);
expect(routeServiceMock.getHistory).toHaveBeenCalled();
expect(routerStub.navigate).toHaveBeenCalledWith(['/']);
});
}); });
}); });

View File

@@ -54,7 +54,7 @@ export class ServerAuthService extends AuthService {
/** /**
* Redirect to the route navigated before the login * Redirect to the route navigated before the login
*/ */
public redirectToPreviousUrl() { public redirectToPreviousUrl(isStandalonePage: boolean) {
this.getRedirectUrl().pipe( this.getRedirectUrl().pipe(
take(1)) take(1))
.subscribe((redirectUrl) => { .subscribe((redirectUrl) => {

View File

@@ -13,13 +13,6 @@ import { TranslateModule } from '@ngx-translate/core';
import { AuthService } from '../../core/auth/auth.service'; import { AuthService } from '../../core/auth/auth.service';
import { AuthServiceStub } from '../testing/auth-service-stub'; import { AuthServiceStub } from '../testing/auth-service-stub';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
import {AppRoutingModule} from '../../app-routing.module';
import {PageNotFoundComponent} from '../../pagenotfound/pagenotfound.component';
import {APP_BASE_HREF} from '@angular/common';
import {RouterStub} from '../testing/router-stub';
import {Router} from '@angular/router';
import {RouteService} from '../services/route.service';
import {routeServiceStub} from '../testing/route-service-stub';
describe('LogInComponent', () => { describe('LogInComponent', () => {
@@ -45,18 +38,13 @@ describe('LogInComponent', () => {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
StoreModule.forRoot(authReducer), StoreModule.forRoot(authReducer),
AppRoutingModule,
TranslateModule.forRoot() TranslateModule.forRoot()
], ],
declarations: [ declarations: [
LogInComponent, LogInComponent
PageNotFoundComponent
], ],
providers: [ providers: [
{provide: AuthService, useClass: AuthServiceStub}, {provide: AuthService, useClass: AuthServiceStub}
{provide: APP_BASE_HREF, useValue: '/'},
{provide: Router, useClass: RouterStub},
{provide: RouteService, useValue: routeServiceStub }
], ],
schemas: [ schemas: [
CUSTOM_ELEMENTS_SCHEMA CUSTOM_ELEMENTS_SCHEMA

View File

@@ -88,7 +88,6 @@ export class LogInComponent implements OnDestroy, OnInit {
* @constructor * @constructor
* @param {AuthService} authService * @param {AuthService} authService
* @param {FormBuilder} formBuilder * @param {FormBuilder} formBuilder
* @param {RouteService} routeService
* @param {Router} router * @param {Router} router
* @param {Store<State>} store * @param {Store<State>} store
*/ */

View File

@@ -64,7 +64,7 @@ export function createTranslateLoader() {
{ {
provide: SubmissionService, provide: SubmissionService,
useClass: ServerSubmissionService useClass: ServerSubmissionService
}, }
] ]
}) })
export class ServerAppModule { export class ServerAppModule {