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
|
import {RecreateResolver} from "./recreate.resolver";
import {getTestBed, TestBed} from '@angular/core/testing';
import {NgRedux} from "@angular-redux/store";
import {InstantiationTemplatesService} from "../../services/templateService/instantiationTemplates.service";
import {AaiService} from "../../services/aaiService/aai.service";
import {mock} from "ts-mockito";
import {ServiceInstance} from "../../models/serviceInstance";
import {HttpClientTestingModule} from "@angular/common/http/testing";
import {FeatureFlagsService} from "../../services/featureFlag/feature-flags.service";
import {convertToParamMap} from "@angular/router";
import {of} from 'rxjs/observable/of'
class MockAppStore<T> {
getState() {}
}
describe('Recreate resolver', () => {
let injector;
let recreateResolver: RecreateResolver;
let aaiService: AaiService;
let instantiationTemplatesService: InstantiationTemplatesService;
beforeAll(done => (async () => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
FeatureFlagsService,
InstantiationTemplatesService,
RecreateResolver,
AaiService,
{provide: NgRedux, useClass: MockAppStore},
]
});
await TestBed.compileComponents();
injector = getTestBed();
recreateResolver = injector.get(RecreateResolver);
aaiService = injector.get(AaiService);
instantiationTemplatesService = injector.get(InstantiationTemplatesService);
})().then(done).catch(done.fail));
test("when resolve() invoked -> then getServiceModelById and retrieveAndStoreInstantiationTemplateTopology are called", done => {
jest.spyOn(aaiService, 'getServiceModelById')
.mockReturnValue(of({}));
jest.spyOn(instantiationTemplatesService, 'retrieveAndStoreInstantiationTemplateTopology')
.mockReturnValue(of(mock(ServiceInstance)));
recreateResolver.resolve(<any>{
queryParamMap:
convertToParamMap({
serviceModelId: "someServiceModelId",
jobId: "someJobId",
})
})
.subscribe(() => {
expect(aaiService.getServiceModelById)
.toHaveBeenCalledWith("someServiceModelId");
expect(instantiationTemplatesService.retrieveAndStoreInstantiationTemplateTopology)
.toHaveBeenCalledWith("someJobId", "someServiceModelId");
done();
});
})
});
|