diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b3ca54cd..65e3cc26 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -18,6 +18,11 @@ const routes: Routes = [ pathMatch: 'full', component: AuthDashboardComponent }, + { + path: 'auth', + pathMatch: 'full', + component: AuthDashboardComponent + }, { path: 'cla/project/:projectId/user/:userId', pathMatch: 'full', diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts index b3551d6d..470f4a9d 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts @@ -2,27 +2,64 @@ // SPDX-License-Identifier: MIT import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Router } from '@angular/router'; +import { AppSettings } from 'src/app/config/app-settings'; +import { StorageService } from 'src/app/shared/services/storage.service'; import { AuthDashboardComponent } from './auth-dashboard.component'; describe('AuthDashboardComponent', () => { let component: AuthDashboardComponent; let fixture: ComponentFixture; + let routerSpy: jasmine.SpyObj; + let storageSpy: jasmine.SpyObj; beforeEach(async () => { + routerSpy = jasmine.createSpyObj('Router', ['navigate']); + storageSpy = jasmine.createSpyObj('StorageService', ['getItem']); + storageSpy.getItem.and.returnValue(null); + await TestBed.configureTestingModule({ - declarations: [ AuthDashboardComponent ] - }) - .compileComponents(); + declarations: [AuthDashboardComponent], + providers: [ + { provide: Router, useValue: routerSpy }, + { provide: StorageService, useValue: storageSpy } + ] + }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(AuthDashboardComponent); component = fixture.componentInstance; - fixture.detectChanges(); }); it('should create', () => { + fixture.detectChanges(); expect(component).toBeTruthy(); }); + + it('navigates to /cla/project/:projectId/user/:userId with redirect query param on init', () => { + storageSpy.getItem.and.callFake(((key: string) => { + switch (key) { + case AppSettings.PROJECT_ID: + return JSON.stringify('proj-123'); + case AppSettings.USER_ID: + return JSON.stringify('user-456'); + case AppSettings.REDIRECT: + return JSON.stringify('https://github.com/foo/bar/pull/42'); + default: + return null; + } + }) as (key: string) => T); + + fixture.detectChanges(); + + expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.PROJECT_ID); + expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.USER_ID); + expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.REDIRECT); + expect(routerSpy.navigate).toHaveBeenCalledOnceWith( + ['/cla/project/proj-123/user/user-456'], + { queryParams: { redirect: 'https://github.com/foo/bar/pull/42' } } + ); + }); });