Skip to content

Commit

Permalink
Revert "Fix: Fix tests and imports"
Browse files Browse the repository at this point in the history
This reverts commit eeed03d.
  • Loading branch information
bistaastha committed Oct 16, 2023
1 parent eeed03d commit 2601e3a
Show file tree
Hide file tree
Showing 12 changed files with 1,232 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/app/core/mock-data/modal-controller.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FyAddToReportModalComponent } from 'src/app/shared/components/fy-add-to
import { reportOptionsData } from './report-options.data';
import { expectedErpt } from './report-unflattened.data';
import { FyInputPopoverComponent } from 'src/app/shared/components/fy-input-popover/fy-input-popover.component';
import { PolicyViolationDialogComponent } from 'src/app/fyle/add-edit-advance-request/policy-violation-dialog/policy-violation-dialog.component';
import { CaptureReceiptComponent } from 'src/app/shared/components/capture-receipt/capture-receipt.component';
import { FyViewAttachmentComponent } from 'src/app/shared/components/fy-view-attachment/fy-view-attachment.component';
import { advanceRequestFileUrlData2, fileObject4 } from './file-object.data';
Expand Down Expand Up @@ -373,6 +374,25 @@ export const popoverControllerParams3 = {
cssClass: 'fy-dialog-popover',
};

export const advanceRequestPolicyViolationParams = {
component: PolicyViolationDialogComponent,
componentProps: {
latestComment: 'latest comment',
violatedPolicyRules: ['rule1', 'rule2'],
policyViolationActionDescription:
'The expense will be flagged, employee will be alerted, expense will be made unreportable and expense amount will be capped to the amount limit.',
},
mode: 'ios' as Mode,
cssClass: 'fy-modal',
showBackdrop: true,
canDismiss: true,
backdropDismiss: true,
animated: true,
initialBreakpoint: 1,
breakpoints: [0, 1],
handle: false,
};

export const popoverControllerParams4 = {
component: PopupAlertComponent,
componentProps: {
Expand Down
59 changes: 59 additions & 0 deletions src/app/core/services/advance-request-policy.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TestBed } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { AdvanceRequestPolicyService } from './advance-request-policy.service';
import { of } from 'rxjs';
import { checkPolicyData, checkPolicyWithRulesData } from '../mock-data/policy-violation-check.data';
import { advanceRequests } from '../mock-data/advance-requests.data';
import { PolicyViolationCheck } from '../models/policy-violation-check.model';

describe('AdvanceRequestPolicyService', () => {
const rootUrl = 'https://staging.fyle.tech';
let advanceRequestPolicyService: AdvanceRequestPolicyService;
let httpClient: jasmine.SpyObj<HttpClient>;

beforeEach(() => {
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['get', 'post']);

TestBed.configureTestingModule({
providers: [
AdvanceRequestPolicyService,
{
provide: HttpClient,
useValue: httpClientSpy,
},
],
});
advanceRequestPolicyService = TestBed.inject(AdvanceRequestPolicyService);
httpClient = TestBed.inject(HttpClient) as jasmine.SpyObj<HttpClient>;

advanceRequestPolicyService.setRoot(rootUrl);
});

it('should be created', () => {
expect(advanceRequestPolicyService).toBeTruthy();
});

it('setRoot(): should set root url', () => {
expect(advanceRequestPolicyService.ROOT_ENDPOINT).toBe(rootUrl);
});

it('getPolicyRules() : shoulg get the poilcy rules', () => {
const expectedRules = ['Policy rule 1', 'Policy rule 3'];
const result = advanceRequestPolicyService.getPolicyRules(checkPolicyWithRulesData);
expect(result).toEqual(expectedRules);
});

it('servicePost(): should make POST request', (done) => {
const apiResponse = checkPolicyData;
httpClient.post.and.returnValue(of(apiResponse));

advanceRequestPolicyService.servicePost<PolicyViolationCheck>('/policy_check', advanceRequests).subscribe((res) => {
expect(res).toEqual(apiResponse);
expect(httpClient.post).toHaveBeenCalledOnceWith(
'https://staging.fyle.tech/policy/advance_requests/policy_check',
advanceRequests
);
done();
});
});
});
31 changes: 31 additions & 0 deletions src/app/core/services/advance-request-policy.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { PolicyViolationCheck } from '../models/policy-violation-check.model';
import { AdvanceRequests } from '../models/advance-requests.model';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class AdvanceRequestPolicyService {
ROOT_ENDPOINT: string;

constructor(private httpClient: HttpClient) {
this.ROOT_ENDPOINT = environment.ROOT_URL;
}

setRoot(rootUrl: string): void {
this.ROOT_ENDPOINT = rootUrl;
}

getPolicyRules(result: PolicyViolationCheck): string[] {
return result.advance_request_policy_rule_desired_states
.filter((desiredState) => desiredState.popup === true)
.map((desiredState) => desiredState.description);
}

servicePost<T>(url: string, data: Partial<AdvanceRequests>): Observable<T> {
return this.httpClient.post<T>(this.ROOT_ENDPOINT + '/policy/advance_requests' + url, data);
}
}
30 changes: 30 additions & 0 deletions src/app/core/services/advance-request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { apiAdvanceReqRes } from '../mock-data/stats-dimension-response.data';
import { AdvancesStates } from '../models/advances-states.model';
import { SortingDirection } from '../models/sorting-direction.model';
import { SortingParam } from '../models/sorting-param.model';
import { AdvanceRequestPolicyService } from './advance-request-policy.service';
import { AdvanceRequestService } from './advance-request.service';
import { ApiV2Service } from './api-v2.service';
import { ApiService } from './api.service';
Expand All @@ -61,6 +62,7 @@ describe('AdvanceRequestService', () => {
let apiService: jasmine.SpyObj<ApiService>;
let apiv2Service: jasmine.SpyObj<ApiV2Service>;
let authService: jasmine.SpyObj<AuthService>;
let advanceRequestPolicyService: jasmine.SpyObj<AdvanceRequestPolicyService>;
let dataTransformService: jasmine.SpyObj<DataTransformService>;
let dateService: DateService;
let fileService: jasmine.SpyObj<FileService>;
Expand All @@ -71,6 +73,7 @@ describe('AdvanceRequestService', () => {
const apiServiceSpy = jasmine.createSpyObj('ApiService', ['get', 'post', 'delete']);
const apiv2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get']);
const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']);
const advanceRequestPolicyServiceSpy = jasmine.createSpyObj('AdvanceRequestPolicyService', ['servicePost']);
const dataTransformServiceSpy = jasmine.createSpyObj('DataTransformService', ['unflatten']);
const fileServiceSpy = jasmine.createSpyObj('FileService', ['post']);
const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']);
Expand All @@ -92,6 +95,10 @@ describe('AdvanceRequestService', () => {
provide: AuthService,
useValue: authServiceSpy,
},
{
provide: AdvanceRequestPolicyService,
useValue: advanceRequestPolicyServiceSpy,
},
{
provide: DataTransformService,
useValue: dataTransformServiceSpy,
Expand All @@ -115,6 +122,9 @@ describe('AdvanceRequestService', () => {
apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
apiv2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
advanceRequestPolicyService = TestBed.inject(
AdvanceRequestPolicyService
) as jasmine.SpyObj<AdvanceRequestPolicyService>;
dataTransformService = TestBed.inject(DataTransformService) as jasmine.SpyObj<DataTransformService>;
fileService = TestBed.inject(FileService) as jasmine.SpyObj<FileService>;
orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj<OrgUserSettingsService>;
Expand Down Expand Up @@ -545,6 +555,26 @@ describe('AdvanceRequestService', () => {
});
});

it('testPolicy(): should test policy violations', (done) => {
const date = '2023-02-23T19:37:01.207Z';
orgUserSettingsService.get.and.returnValue(of(orgUserSettingsData));
advanceRequestPolicyService.servicePost.and.returnValue(of(checkPolicyData));
timezoneService.convertToUtc.and.returnValue(new Date(date));

advanceRequestService.testPolicy(checkPolicyAdvReqParam).subscribe((res) => {
expect(res).toEqual(checkPolicyData);
expect(timezoneService.convertToUtc).toHaveBeenCalledOnceWith(
checkPolicyAdvReqParam.created_at,
orgUserSettingsData.locale.offset
);
expect(advanceRequestPolicyService.servicePost).toHaveBeenCalledOnceWith(
'/policy_check/test',
checkPolicyAdvReqParam
);
done();
});
});

it('getTeamAdvanceRequestsCount(): should get team advance count', (done) => {
spyOn(advanceRequestService, 'getTeamAdvanceRequests').and.returnValue(of(teamAdvanceCountRes));

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/services/advance-request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class AdvanceRequestService {
);
}

getActions(advanceRequestId: string): Observable<AdvanceRequestActions> {
getActions(advanceRequestId: string) {
return this.apiService.get('/advance_requests/' + advanceRequestId + '/actions');
}

Expand Down
11 changes: 11 additions & 0 deletions src/app/core/services/router-auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RouterAuthService } from './router-auth.service';
import { RouterApiService } from './router-api.service';
import { StorageService } from './storage.service';
import { TokenService } from './token.service';
import { AdvanceRequestPolicyService } from './advance-request-policy.service';
import { ApiService } from './api.service';
import { ApiV2Service } from './api-v2.service';
import { LocationService } from './location.service';
Expand All @@ -20,6 +21,7 @@ describe('RouterAuthService', () => {
let routerApiService: jasmine.SpyObj<RouterApiService>;
let storageService: jasmine.SpyObj<StorageService>;
let tokenService: jasmine.SpyObj<TokenService>;
let advanceRequestPolicyService: jasmine.SpyObj<AdvanceRequestPolicyService>;
let apiService: jasmine.SpyObj<ApiService>;
let apiV2Service: jasmine.SpyObj<ApiV2Service>;
let locationService: jasmine.SpyObj<LocationService>;
Expand Down Expand Up @@ -47,6 +49,7 @@ describe('RouterAuthService', () => {
'setClusterDomain',
'setAccessToken',
]);
const advanceRequestPolicyServiceSpy = jasmine.createSpyObj('AdvanceRequestPolicyService', ['setRoot']);
const apiServiceSpy = jasmine.createSpyObj('ApiService', ['setRoot']);
const apiV2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['setRoot']);
const locationServiceSpy = jasmine.createSpyObj('LocationService', ['setRoot']);
Expand All @@ -71,6 +74,10 @@ describe('RouterAuthService', () => {
provide: TokenService,
useValue: tokenServiceSpy,
},
{
provide: AdvanceRequestPolicyService,
useValue: advanceRequestPolicyServiceSpy,
},
{
provide: ApiService,
useValue: apiServiceSpy,
Expand Down Expand Up @@ -113,6 +120,9 @@ describe('RouterAuthService', () => {
routerApiService = TestBed.inject(RouterApiService) as jasmine.SpyObj<RouterApiService>;
storageService = TestBed.inject(StorageService) as jasmine.SpyObj<StorageService>;
tokenService = TestBed.inject(TokenService) as jasmine.SpyObj<TokenService>;
advanceRequestPolicyService = TestBed.inject(
AdvanceRequestPolicyService
) as jasmine.SpyObj<AdvanceRequestPolicyService>;
apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
locationService = TestBed.inject(LocationService) as jasmine.SpyObj<LocationService>;
Expand Down Expand Up @@ -149,6 +159,7 @@ describe('RouterAuthService', () => {

routerAuthService.setClusterDomain(domain).then((res) => {
expect(apiService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(advanceRequestPolicyService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(apiV2Service.setRoot).toHaveBeenCalledOnceWith(domain);
expect(locationService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(transactionOutboxService.setRoot).toHaveBeenCalledOnceWith(domain);
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/services/router-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TokenService } from './token.service';
import { ApiService } from './api.service';
import { AuthResponse } from '../models/auth-response.model';
import { Observable, from } from 'rxjs';
import { AdvanceRequestPolicyService } from './advance-request-policy.service';
import { ApiV2Service } from './api-v2.service';
import { LocationService } from './location.service';
import { TransactionsOutboxService } from './transactions-outbox.service';
Expand All @@ -23,6 +24,7 @@ export class RouterAuthService {
private routerApiService: RouterApiService,
private storageService: StorageService,
private tokenService: TokenService,
private advanceRequestPolicyService: AdvanceRequestPolicyService,
private apiService: ApiService,
private apiv2Service: ApiV2Service,
private locationService: LocationService,
Expand Down Expand Up @@ -52,6 +54,7 @@ export class RouterAuthService {

async setClusterDomain(domain) {
this.apiService.setRoot(domain);
this.advanceRequestPolicyService.setRoot(domain);
this.apiv2Service.setRoot(domain);
this.locationService.setRoot(domain);
this.transactionOutboxService.setRoot(domain);
Expand Down
Loading

0 comments on commit 2601e3a

Please sign in to comment.