Fixing SO-Monitoring UI tests
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / data.service.spec.ts
index 987d29d..834b8c3 100644 (file)
@@ -23,15 +23,88 @@ SPDX-License-Identifier: Apache-2.0
 import { TestBed, inject } from '@angular/core/testing';\r
 \r
 import { DataService } from './data.service';\r
+import { HttpClient } from '@angular/common/http';\r
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';\r
+import { async } from '@angular/core/testing';\r
+import { HttpClientModule } from '@angular/common/http';\r
+import { ToastrNotificationService } from './toastr-notification-service.service';\r
+import { environment } from '../environments/environment';\r
+\r
+class StubbedToastrNotificationService extends ToastrNotificationService {\r
+  toastrSettings() {\r
+  }\r
+}\r
 \r
 describe('DataService', () => {\r
   beforeEach(() => {\r
     TestBed.configureTestingModule({\r
-      providers: [DataService]\r
+      providers: [DataService, { provide: ToastrNotificationService, useClass: StubbedToastrNotificationService }],\r
+      imports: [HttpClientTestingModule]\r
     });\r
   });\r
 \r
-  it('should be created', inject([DataService], (service: DataService) => {\r
-    expect(service).toBeTruthy();\r
-  }));\r
+  // Ensure creation of DataService component\r
+  it('component should be created', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      expect(service).toBeTruthy();\r
+    })));\r
+\r
+  // Test retrieveInstance function making POST call\r
+  it('test retrieveInstance POST request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.retrieveInstance({}, 1, 2).subscribe(data => { });\r
+      var url = environment.soMonitoringBackendURL + 'v1/search?from=1&to=2';\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('POST');\r
+      mockReq.flush({});\r
+    })));\r
+\r
+  // Test getProcessInstanceId function making GET request to retrieve processInstanceID\r
+  it('test getProcessInstanceId GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.getProcessInstanceId("").subscribe(data => { });\r
+      var url = environment.soMonitoringBackendURL + 'process-instance-id/' + "";\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('GET');\r
+      mockReq.flush({});\r
+    })));\r
+\r
+  // Test getActivityInstance function making GET request to retrieve activityInstance\r
+  it('test getActivityInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.getActivityInstance("").subscribe(data => { });\r
+      var url = environment.soMonitoringBackendURL + 'activity-instance/' + "";\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('GET');\r
+      mockReq.flush({});\r
+    })));\r
+\r
+  // Test getProcessInstance function making GET request to retrieve processInstance\r
+  it('test getProcessInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.getProcessInstance("");\r
+      var url = environment.soMonitoringBackendURL + 'process-instance/' + "";\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('GET');\r
+    })));\r
+\r
+  // Test getProcessDefinition function making GET request to retrieve processDefinition\r
+  it('test getProcessDefinition GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.getProcessDefinition("").subscribe(data => { });\r
+      var url = environment.soMonitoringBackendURL + 'process-definition/' + "";\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('GET');\r
+      mockReq.flush({});\r
+    })));\r
+\r
+  // Test getVariableInstance function making GET request to retrieve variableInstance\r
+  it('test getVariableInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
+    (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
+      service.getVariableInstance("").subscribe(data => { });\r
+      var url = environment.soMonitoringBackendURL + 'variable-instance/' + "";\r
+      const mockReq = httpClient.expectOne(url);\r
+      expect(mockReq.request.method).toEqual('GET');\r
+      mockReq.flush({});\r
+    })));\r
 });\r