]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
2 | import { TestBed } from '@angular/core/testing'; | |
3 | ||
4 | import { configureTestBed } from '../../../testing/unit-test-helper'; | |
5 | import { IscsiService } from './iscsi.service'; | |
6 | ||
7 | describe('IscsiService', () => { | |
8 | let service: IscsiService; | |
9 | let httpTesting: HttpTestingController; | |
10 | ||
11 | configureTestBed({ | |
12 | providers: [IscsiService], | |
13 | imports: [HttpClientTestingModule] | |
14 | }); | |
15 | ||
16 | beforeEach(() => { | |
17 | service = TestBed.get(IscsiService); | |
18 | httpTesting = TestBed.get(HttpTestingController); | |
19 | }); | |
20 | ||
21 | afterEach(() => { | |
22 | httpTesting.verify(); | |
23 | }); | |
24 | ||
25 | it('should be created', () => { | |
26 | expect(service).toBeTruthy(); | |
27 | }); | |
28 | ||
29 | it('should call listTargets', () => { | |
30 | service.listTargets().subscribe(); | |
31 | const req = httpTesting.expectOne('api/iscsi/target'); | |
32 | expect(req.request.method).toBe('GET'); | |
33 | }); | |
34 | ||
35 | it('should call getTarget', () => { | |
36 | service.getTarget('iqn.foo').subscribe(); | |
37 | const req = httpTesting.expectOne('api/iscsi/target/iqn.foo'); | |
38 | expect(req.request.method).toBe('GET'); | |
39 | }); | |
40 | ||
41 | it('should call status', () => { | |
42 | service.status().subscribe(); | |
43 | const req = httpTesting.expectOne('ui-api/iscsi/status'); | |
44 | expect(req.request.method).toBe('GET'); | |
45 | }); | |
46 | ||
47 | it('should call settings', () => { | |
48 | service.settings().subscribe(); | |
49 | const req = httpTesting.expectOne('ui-api/iscsi/settings'); | |
50 | expect(req.request.method).toBe('GET'); | |
51 | }); | |
52 | ||
53 | it('should call portals', () => { | |
54 | service.portals().subscribe(); | |
55 | const req = httpTesting.expectOne('ui-api/iscsi/portals'); | |
56 | expect(req.request.method).toBe('GET'); | |
57 | }); | |
58 | ||
59 | it('should call createTarget', () => { | |
60 | service.createTarget({ target_iqn: 'foo' }).subscribe(); | |
61 | const req = httpTesting.expectOne('api/iscsi/target'); | |
62 | expect(req.request.method).toBe('POST'); | |
63 | expect(req.request.body).toEqual({ target_iqn: 'foo' }); | |
64 | }); | |
65 | ||
66 | it('should call updateTarget', () => { | |
67 | service.updateTarget('iqn.foo', { target_iqn: 'foo' }).subscribe(); | |
68 | const req = httpTesting.expectOne('api/iscsi/target/iqn.foo'); | |
69 | expect(req.request.method).toBe('PUT'); | |
70 | expect(req.request.body).toEqual({ target_iqn: 'foo' }); | |
71 | }); | |
72 | ||
73 | it('should call deleteTarget', () => { | |
74 | service.deleteTarget('target_iqn').subscribe(); | |
75 | const req = httpTesting.expectOne('api/iscsi/target/target_iqn'); | |
76 | expect(req.request.method).toBe('DELETE'); | |
77 | }); | |
78 | ||
79 | it('should call getDiscovery', () => { | |
80 | service.getDiscovery().subscribe(); | |
81 | const req = httpTesting.expectOne('api/iscsi/discoveryauth'); | |
82 | expect(req.request.method).toBe('GET'); | |
83 | }); | |
84 | ||
85 | it('should call updateDiscovery', () => { | |
86 | service | |
87 | .updateDiscovery({ | |
88 | user: 'foo', | |
89 | password: 'bar', | |
90 | mutual_user: 'mutual_foo', | |
91 | mutual_password: 'mutual_bar' | |
92 | }) | |
93 | .subscribe(); | |
94 | const req = httpTesting.expectOne('api/iscsi/discoveryauth'); | |
95 | expect(req.request.method).toBe('PUT'); | |
96 | }); | |
97 | }); |