Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {CalibratorsService} from './calibrators.service';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {TestBed} from "@angular/core/testing/";
import {ConfigurationService} from "../env/configuration.service";
import {Configuration} from "../env/model/configuration";
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"
} as Configuration;
};
}
describe('CalibratorsService', () => {
let httpMock: HttpTestingController;
let calibratorsService: CalibratorsService;
let fakeConfigService: FakeConfigurationService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [CalibratorsService, {provide: ConfigurationService, useClass: FakeConfigurationService}]
});
calibratorsService = TestBed.get(CalibratorsService);
httpMock = TestBed.get(HttpTestingController);
fakeConfigService = TestBed.get(ConfigurationService);
});
it('should retrieve calibrators from endpoint', () => {
const calibrations = [{
"id": 734,
"name": "A0004-1148",
"sctCatalogId": null,
"sctId": 1,
"type": null,
"fluxes": [],
"polarization": []
}];
calibratorsService.getCalibrators().subscribe(response => {
expect(response).toEqual(calibrations, 'calibrations');
}, fail);
const req = httpMock.expectOne(fakeConfigService.config.url + calibratorsService.endPoint);
expect(req.request.method).toBe("GET");
req.flush(calibrations);
httpMock.verify();
});
it('should create a calibration', () => {
const flux = {
frequency: 12.3,
flux: 45,
spectralIndex: 67,
observingDate: null,
uvMin: 8,
uvMax: 9,
id: 123
};
calibratorsService.saveCalibratorFlux(734, 123, 12.3, 45, 67, 8, 9).subscribe(response => {
console.log('response type:', typeof response);
expect(Object.assign({}, response)).toEqual(Object.assign({}, flux), 'create flux');
});
const req = httpMock.expectOne(fakeConfigService.config.url + calibratorsService.endPoint + '734/flux/123');
expect(req.request.method).toBe("POST");
req.flush(flux);
httpMock.verify();
});
});