Skip to content
Snippets Groups Projects
tiles.service.spec.ts 2.96 KiB
Newer Older
import {TilesService} from './tiles.service';
import {Tile, TileDefinition} from "../model/tile";
import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing";
import {TestBed} from "@angular/core/testing";
import {ConfigurationService} from "../env/configuration.service";
import {RouterTestingModule} from "@angular/router/testing";

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('TilesService', () => {

  let httpMock: HttpTestingController;
  let tilesService: TilesService;
  let fakeConfigService: FakeConfigurationService;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])],
      providers: [TilesService, {provide: ConfigurationService, useClass: FakeConfigurationService}]
    });

    tilesService = TestBed.get(TilesService);
    httpMock = TestBed.get(HttpTestingController);
    fakeConfigService = TestBed.get(ConfigurationService);
  });

  it('should get tiles for epoch', () => {
    let expectedResults = [{
      area: 23.64,
      custom1: "VLASS1.1",
      custom2: "2018-02-07",
      custom3: "100% imaged",
      custom4: null,
      custom5: null,
      decMax: -36,
      decMin: -40,
      epoch: 1,
      factor: 1.73,
      firstEpochHalf: true,
      id: 1,
      name: "Tile1",
      raMax: 7.5,
      raMin: 0,
      tier: 1
    } as Tile, {
      area: 23.64,
      custom1: "VLASS1.1",
      custom2: "2018-02-03",
      custom3: "100% imaged",
      custom4: null,
      custom5: null,
      decMax: -36,
      decMin: -40,
      epoch: 1,
      factor: 1.73,
      firstEpochHalf: true,
      id: 2,
      name: "Tile2",
      raMax: 15,
      raMin: 7.5,
      tier: 1
    } as Tile
    ];

    tilesService.getTilesForEpoch(null, 1).subscribe(response => {
      console.log('called gtfe');
      expect(response).toEqual(expectedResults, 'get epoch tiles');
    });

    const req = httpMock.expectOne(req => req.url === fakeConfigService.config.url + tilesService.endPoint + 'summary/epoch/1');
    expect(req.request.method).toBe("GET");
    req.flush(expectedResults);

    httpMock.verify();
  });

  it('should get tile definition', () => {
    let expectedResults = {
      coarseCenterFrequenciesMHz: [],
      phaseCentersDeg: []
    } as TileDefinition;

    tilesService.getTileDefinition(1).subscribe(response => {
      expect(response).toEqual(expectedResults, 'get tile definition');
    });

    const req = httpMock.expectOne(fakeConfigService.config.url + tilesService.endPoint + '1/definitions');
    expect(req.request.method).toBe("GET");
    req.flush(expectedResults);

    httpMock.verify();
  });
});