]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
a4b75251 | 2 | import { fakeAsync, TestBed, tick } from '@angular/core/testing'; |
11fdf7f2 | 3 | |
f67539c2 | 4 | import { configureTestBed } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
5 | import { NfsService } from './nfs.service'; |
6 | ||
7 | describe('NfsService', () => { | |
8 | let service: NfsService; | |
9 | let httpTesting: HttpTestingController; | |
10 | ||
11 | configureTestBed({ | |
f67539c2 | 12 | providers: [NfsService], |
11fdf7f2 TL |
13 | imports: [HttpClientTestingModule] |
14 | }); | |
15 | ||
16 | beforeEach(() => { | |
f67539c2 TL |
17 | service = TestBed.inject(NfsService); |
18 | httpTesting = TestBed.inject(HttpTestingController); | |
11fdf7f2 TL |
19 | }); |
20 | ||
21 | afterEach(() => { | |
22 | httpTesting.verify(); | |
23 | }); | |
24 | ||
25 | it('should be created', () => { | |
26 | expect(service).toBeTruthy(); | |
27 | }); | |
28 | ||
29 | it('should call list', () => { | |
30 | service.list().subscribe(); | |
31 | const req = httpTesting.expectOne('api/nfs-ganesha/export'); | |
32 | expect(req.request.method).toBe('GET'); | |
33 | }); | |
34 | ||
35 | it('should call get', () => { | |
36 | service.get('cluster_id', 'export_id').subscribe(); | |
37 | const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster_id/export_id'); | |
38 | expect(req.request.method).toBe('GET'); | |
39 | }); | |
40 | ||
41 | it('should call create', () => { | |
42 | service.create('foo').subscribe(); | |
43 | const req = httpTesting.expectOne('api/nfs-ganesha/export'); | |
44 | expect(req.request.method).toBe('POST'); | |
45 | expect(req.request.body).toEqual('foo'); | |
46 | }); | |
47 | ||
48 | it('should call update', () => { | |
a4b75251 TL |
49 | service.update('cluster_id', 1, 'foo').subscribe(); |
50 | const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster_id/1'); | |
11fdf7f2 TL |
51 | expect(req.request.body).toEqual('foo'); |
52 | expect(req.request.method).toBe('PUT'); | |
53 | }); | |
54 | ||
55 | it('should call delete', () => { | |
56 | service.delete('hostName', 'exportId').subscribe(); | |
57 | const req = httpTesting.expectOne('api/nfs-ganesha/export/hostName/exportId'); | |
58 | expect(req.request.method).toBe('DELETE'); | |
59 | }); | |
60 | ||
61 | it('should call lsDir', () => { | |
f91f0fd5 TL |
62 | service.lsDir('a', 'foo_dir').subscribe(); |
63 | const req = httpTesting.expectOne('ui-api/nfs-ganesha/lsdir/a?root_dir=foo_dir'); | |
11fdf7f2 TL |
64 | expect(req.request.method).toBe('GET'); |
65 | }); | |
66 | ||
a4b75251 TL |
67 | it('should not call lsDir if volume is not provided', fakeAsync(() => { |
68 | service.lsDir('', 'foo_dir').subscribe({ | |
69 | error: (error: string) => expect(error).toEqual('Please specify a filesystem volume.') | |
70 | }); | |
71 | tick(); | |
72 | httpTesting.expectNone('ui-api/nfs-ganesha/lsdir/?root_dir=foo_dir'); | |
73 | })); | |
11fdf7f2 | 74 | }); |