import {SchedblocksService} from './schedblocks.service'; import {Schedblock} from "../model/schedblock"; import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; import {TestBed} from "@angular/core/testing"; import {ConfigurationService} from "../env/configuration.service"; export class FakeConfigurationService { get config() { return { dryrun: "false", rootDataDirectory: "/lustre/aoc/cluster/pipeline/vlass_test/spool", url: "http://localhost:4200/VlassMngr", weblogbaseurl: "http://webtest.aoc.nrao.edu/", projectcode: "VLASS1.1", wsurl: "ws://localhost:8081/VlassMngr/changes", currentepoch: "1" }; } } describe('SchedblocksService', () => { let httpMock: HttpTestingController; let schedblocksService: SchedblocksService; let fakeConfigService: FakeConfigurationService; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], providers: [SchedblocksService, {provide: ConfigurationService, useClass: FakeConfigurationService}] }); schedblocksService = TestBed.get(SchedblocksService); httpMock = TestBed.get(HttpTestingController); fakeConfigService = TestBed.get(ConfigurationService); }); it('should be get schedblocks', () => { let expectedResponse = [{ category: "SCHEDBLOCK", completed: false, configurations: [], epoch: 1, extraInfoForJobName: "", fileNames: [], fluxCalibrators: [], fluxPosition: null, id: 1, latestProductVersion: {present: true}, lstEnd: null, lstStart: null, minitiles: [], name: "SchedBlock1", notes: null, optId: 2, phaseCalibrators: [], polCalibrators: [], preRequisites: [], status: "COMPLETED", submitted: null, tags: [], typeId: 11, typeName: "schedblock", versions: [] } as Schedblock, { category: "SCHEDBLOCK", completed: false, configurations: [], epoch: 1, extraInfoForJobName: "", fileNames: [], fluxCalibrators: [], fluxPosition: null, id: 2, latestProductVersion: {present: true}, lstEnd: null, lstStart: null, minitiles: [], name: "SchedBlock2", notes: null, optId: 3, phaseCalibrators: [], polCalibrators: [], preRequisites: [], status: "COMPLETED", submitted: null, tags: [], typeId: 11, typeName: "schedblock", versions: [] } as Schedblock]; schedblocksService.getSchedblocks().subscribe(response => { expect(response).toEqual(expectedResponse, 'get schedblocks'); }); const req = httpMock.expectOne(fakeConfigService.config.url + schedblocksService.endPoint); expect(req.request.method).toBe("GET"); req.flush(expectedResponse); httpMock.verify(); }); it('should create a schedblock', () => { let expectedResponse = { category: "SCHEDBLOCK", completed: false, configurations: [], epoch: 1, extraInfoForJobName: "", fileNames: [], fluxCalibrators: [], fluxPosition: null, id: 1, latestProductVersion: {present: true}, lstEnd: null, lstStart: null, minitiles: [], name: "SchedBlock1", notes: null, optId: 2, phaseCalibrators: [], polCalibrators: [], preRequisites: [], status: "COMPLETED", submitted: null, tags: [], typeId: 11, typeName: "schedblock", versions: [] } as Schedblock; schedblocksService.createSchedblock('1', 'SchedBlock1', 2, '123456').subscribe(response => { expect(response).toEqual(expectedResponse, 'create schedblocks'); }); const req = httpMock.expectOne(fakeConfigService.config.url + schedblocksService.endPoint + 'generateEverything'); expect(req.request.method).toBe("POST"); req.flush(expectedResponse); httpMock.verify(); }); });