Add test Coverage for Policy Service
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / services / policy / policy.service.ts
index c5ee579..f24747b 100644 (file)
@@ -34,8 +34,8 @@ import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.type
 export class PolicyService {
 
     private basePath = 'api/policy';
-    private policyTypePath = 'policytypes';
-    private policyPath = 'policies';
+    policyTypePath = 'policytypes';
+    policyPath = 'policies';
 
     private buildPath(...args: any[]) {
         let result = this.basePath;
@@ -67,7 +67,7 @@ export class PolicyService {
     }
 
     getPolicyInstances(policyTypeId: string): Observable<PolicyInstance[]> {
-        const url = this.buildPath(this.policyTypePath, policyTypeId, this.policyPath);
+        const url = this.buildPath(this.policyPath) + '?type=' + policyTypeId;
         return this.httpClient.get<PolicyInstance[]>(url);
     }
 
@@ -76,7 +76,7 @@ export class PolicyService {
      * @returns Observable that should yield a policy instance
      */
     getPolicy(policyTypeId: string, policyInstanceId: string): Observable<any> {
-        const url = this.buildPath(this.policyTypePath, policyTypeId, this.policyPath, policyInstanceId);
+        const url = this.buildPath(this.policyPath, policyInstanceId) + '?type=' + policyTypeId;
         return this.httpClient.get<any>(url);
     }
 
@@ -88,17 +88,18 @@ export class PolicyService {
      * @returns Observable that should yield a response code, no data
      */
     putPolicy(policyTypeId: string, policyInstanceId: string, policyJson: string, ric: string): Observable<any> {
-        const url = this.buildPath(this.policyTypePath, policyTypeId, this.policyPath, policyInstanceId) + "?ric=" + ric;
+        const url = this.buildPath(this.policyPath, policyInstanceId) + '?ric=' + ric + '&type=' + policyTypeId;
         return this.httpClient.put<PolicyInstanceAck>(url, policyJson, { observe: 'response' });
     }
 
     /**
      * Deletes a policy instance.
-     * @param policyTypeId
+     * @param policyTypeId ID of the policy type that the instance belong to
+     * @param policyInstanceId ID of the instance
      * @returns Observable that should yield a response code, no data
      */
     deletePolicy(policyTypeId: string, policyInstanceId: string): Observable<any> {
-        const url = this.buildPath(this.policyTypePath, policyTypeId, this.policyPath, policyInstanceId);
+        const url = this.buildPath(this.policyPath, policyInstanceId) + '?type=' + policyTypeId;
         return this.httpClient.delete(url, { observe: 'response' });
     }