-
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.
Showing
12 changed files
with
1,232 additions
and
4 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
59 changes: 59 additions & 0 deletions
59
src/app/core/services/advance-request-policy.service.spec.ts
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,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(); | ||
}); | ||
}); | ||
}); |
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,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); | ||
} | ||
} |
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
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.