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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { configureTestBed } from '~/testing/unit-test-helper';
import { IscsiService } from './iscsi.service';
describe('IscsiService', () => {
let service: IscsiService;
let httpTesting: HttpTestingController;
configureTestBed({
providers: [IscsiService],
imports: [HttpClientTestingModule]
});
beforeEach(() => {
service = TestBed.inject(IscsiService);
httpTesting = TestBed.inject(HttpTestingController);
});
afterEach(() => {
httpTesting.verify();
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('should call listTargets', () => {
service.listTargets().subscribe();
const req = httpTesting.expectOne('api/iscsi/target');
expect(req.request.method).toBe('GET');
});
it('should call getTarget', () => {
service.getTarget('iqn.foo').subscribe();
const req = httpTesting.expectOne('api/iscsi/target/iqn.foo');
expect(req.request.method).toBe('GET');
});
it('should call status', () => {
service.status().subscribe();
const req = httpTesting.expectOne('ui-api/iscsi/status');
expect(req.request.method).toBe('GET');
});
it('should call settings', () => {
service.settings().subscribe();
const req = httpTesting.expectOne('ui-api/iscsi/settings');
expect(req.request.method).toBe('GET');
});
it('should call portals', () => {
service.portals().subscribe();
const req = httpTesting.expectOne('ui-api/iscsi/portals');
expect(req.request.method).toBe('GET');
});
it('should call createTarget', () => {
service.createTarget({ target_iqn: 'foo' }).subscribe();
const req = httpTesting.expectOne('api/iscsi/target');
expect(req.request.method).toBe('POST');
expect(req.request.body).toEqual({ target_iqn: 'foo' });
});
it('should call updateTarget', () => {
service.updateTarget('iqn.foo', { target_iqn: 'foo' }).subscribe();
const req = httpTesting.expectOne('api/iscsi/target/iqn.foo');
expect(req.request.method).toBe('PUT');
expect(req.request.body).toEqual({ target_iqn: 'foo' });
});
it('should call deleteTarget', () => {
service.deleteTarget('target_iqn').subscribe();
const req = httpTesting.expectOne('api/iscsi/target/target_iqn');
expect(req.request.method).toBe('DELETE');
});
it('should call getDiscovery', () => {
service.getDiscovery().subscribe();
const req = httpTesting.expectOne('api/iscsi/discoveryauth');
expect(req.request.method).toBe('GET');
});
it('should call updateDiscovery', () => {
service
.updateDiscovery({
user: 'foo',
password: 'bar',
mutual_user: 'mutual_foo',
mutual_password: 'mutual_bar'
})
.subscribe();
const req = httpTesting.expectOne('api/iscsi/discoveryauth');
expect(req.request.method).toBe('PUT');
});
});
|