-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into FYLE-86cvrjd0e-submit
- Loading branch information
Showing
101 changed files
with
4,364 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum OptInFlowState { | ||
MOBILE_INPUT = 'MOBILE_INPUT', | ||
OTP_VERIFICATION = 'OTP_VERIFICATION', | ||
SUCCESS = 'SUCCESS', | ||
ERROR = 'ERROR', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { OptInGuard } from './opt-in.guard'; | ||
import { UtilityService } from '../services/utility.service'; | ||
import { ActivatedRoute, Router, RouterStateSnapshot } from '@angular/router'; | ||
import { Observable, of } from 'rxjs'; | ||
|
||
describe('OptInGuard', () => { | ||
let guard: OptInGuard; | ||
let utilityService: jasmine.SpyObj<UtilityService>; | ||
let router: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
const utilityServiceSpy = jasmine.createSpyObj('UtilityService', [ | ||
'canShowOptInAfterExpenseCreation', | ||
'canShowOptInModal', | ||
'canShowOptInAfterAddingCard', | ||
]); | ||
const routerSpy = jasmine.createSpyObj('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: UtilityService, | ||
useValue: utilityServiceSpy, | ||
}, | ||
{ | ||
provide: Router, | ||
useValue: routerSpy, | ||
}, | ||
], | ||
}); | ||
guard = TestBed.inject(OptInGuard); | ||
utilityService = TestBed.inject(UtilityService) as jasmine.SpyObj<UtilityService>; | ||
router = TestBed.inject(Router) as jasmine.SpyObj<Router>; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
|
||
describe('canActivate():', () => { | ||
it('should return true if the current route includes "my_expenses" and the next route does not include "add_edit" and canShowOptIn is false', (done) => { | ||
const currentRoute = 'my_expenses'; | ||
const nextRoute = 'my_dashboard'; | ||
const canShowOptIn = false; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterExpenseCreation.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterExpenseCreation).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).not.toHaveBeenCalled(); | ||
expect(res).toBeTrue(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return true if the current route includes "my_expenses" and the next route does not include "add_edit" and canShowOptIn is true', (done) => { | ||
const currentRoute = 'my_expenses'; | ||
const nextRoute = 'my_dashboard'; | ||
const canShowOptIn = true; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterExpenseCreation.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterExpenseCreation).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).toHaveBeenCalledOnceWith({ | ||
feature: 'OPT_IN_POPUP_POST_EXPENSE_CREATION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}); | ||
expect(res).toBeFalse(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return true if the current route includes "my_dashboard" and canShowOptIn is false', (done) => { | ||
const currentRoute = 'my_dashboard'; | ||
const nextRoute = 'my_dashboard'; | ||
const canShowOptIn = false; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterAddingCard.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterAddingCard).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).not.toHaveBeenCalled(); | ||
expect(res).toBeTrue(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return true if the current route includes "my_dashboard" and canShowOptIn is true', (done) => { | ||
const currentRoute = 'my_dashboard'; | ||
const nextRoute = 'my_dashboard'; | ||
const canShowOptIn = true; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterAddingCard.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterAddingCard).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).toHaveBeenCalledOnceWith({ | ||
feature: 'OPT_IN_POPUP_POST_CARD_ADDITION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}); | ||
expect(res).toBeFalse(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return true if the current route includes "manage_corporate_cards" and canShowOptIn is false', (done) => { | ||
const currentRoute = 'manage_corporate_cards'; | ||
const nextRoute = 'manage_corporate_cards'; | ||
const canShowOptIn = false; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterAddingCard.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterAddingCard).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).not.toHaveBeenCalled(); | ||
expect(res).toBeTrue(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return true if the current route includes "manage_corporate_cards" and canShowOptIn is true', (done) => { | ||
const currentRoute = 'manage_corporate_cards'; | ||
const nextRoute = 'manage_corporate_cards'; | ||
const canShowOptIn = true; | ||
const canShowOptInModal = true; | ||
Object.defineProperty(router, 'routerState', { writable: true, value: { snapshot: { url: currentRoute } } }); | ||
utilityService.canShowOptInAfterAddingCard.and.returnValue(canShowOptIn); | ||
utilityService.canShowOptInModal.and.returnValue(of(canShowOptInModal)); | ||
|
||
const canActivate = guard.canActivate(new ActivatedRoute().snapshot, { | ||
url: nextRoute, | ||
} as RouterStateSnapshot) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(utilityService.canShowOptInAfterAddingCard).toHaveBeenCalledTimes(1); | ||
expect(utilityService.canShowOptInModal).toHaveBeenCalledOnceWith({ | ||
feature: 'OPT_IN_POPUP_POST_CARD_ADDITION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}); | ||
expect(res).toBeFalse(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { Observable, map, of } from 'rxjs'; | ||
import { UtilityService } from '../services/utility.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class OptInGuard implements CanActivate { | ||
constructor(private utilityService: UtilityService, private router: Router) {} | ||
|
||
canActivate( | ||
next: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
const currentRoute = this.router.routerState.snapshot.url; | ||
const nextRoute = state.url; | ||
|
||
if (currentRoute.includes('my_expenses') && !nextRoute.includes('add_edit')) { | ||
const canShowOptInPostExpenseCreation = this.utilityService.canShowOptInAfterExpenseCreation(); | ||
|
||
if (!canShowOptInPostExpenseCreation) { | ||
return of(true); | ||
} else { | ||
const optInModalPostExpenseCreationFeatureConfig = { | ||
feature: 'OPT_IN_POPUP_POST_EXPENSE_CREATION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}; | ||
return this.utilityService | ||
.canShowOptInModal(optInModalPostExpenseCreationFeatureConfig) | ||
.pipe(map((canShowOptInModal) => !canShowOptInModal)); | ||
} | ||
} | ||
|
||
if (currentRoute.includes('my_dashboard')) { | ||
const canShowOptInPostCardAddition = this.utilityService.canShowOptInAfterAddingCard(); | ||
|
||
if (!canShowOptInPostCardAddition) { | ||
return of(true); | ||
} else { | ||
const optInModalPostCardAdditionFeatureConfig = { | ||
feature: 'OPT_IN_POPUP_POST_CARD_ADDITION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}; | ||
return this.utilityService | ||
.canShowOptInModal(optInModalPostCardAdditionFeatureConfig) | ||
.pipe(map((canShowOptInModal) => !canShowOptInModal)); | ||
} | ||
} | ||
|
||
if (currentRoute.includes('manage_corporate_cards')) { | ||
const canShowOptInPostCardAddition = this.utilityService.canShowOptInAfterAddingCard(); | ||
|
||
if (!canShowOptInPostCardAddition) { | ||
return of(true); | ||
} else { | ||
const optInModalPostCardAdditionFeatureConfig = { | ||
feature: 'OPT_IN_POPUP_POST_CARD_ADDITION', | ||
key: 'OPT_IN_POPUP_SHOWN_COUNT', | ||
}; | ||
return this.utilityService | ||
.canShowOptInModal(optInModalPostCardAdditionFeatureConfig) | ||
.pipe(map((canShowOptInModal) => !canShowOptInModal)); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.