]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/configuration.service.spec.ts
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / configuration.service.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2import { TestBed } from '@angular/core/testing';
3
4import { configureTestBed } from '../../../testing/unit-test-helper';
5import { ConfigFormCreateRequestModel } from '../../ceph/cluster/configuration/configuration-form/configuration-form-create-request.model';
6import { ConfigurationService } from './configuration.service';
7
8describe('ConfigurationService', () => {
9 let service: ConfigurationService;
10 let httpTesting: HttpTestingController;
11
12 configureTestBed({
13 providers: [ConfigurationService],
14 imports: [HttpClientTestingModule]
15 });
16
17 beforeEach(() => {
18 service = TestBed.get(ConfigurationService);
19 httpTesting = TestBed.get(HttpTestingController);
20 });
21
22 afterEach(() => {
23 httpTesting.verify();
24 });
25
26 it('should be created', () => {
27 expect(service).toBeTruthy();
28 });
29
30 it('should call getConfigData', () => {
31 service.getConfigData().subscribe();
32 const req = httpTesting.expectOne('api/cluster_conf/');
33 expect(req.request.method).toBe('GET');
34 });
35
36 it('should call get', () => {
37 service.get('configOption').subscribe();
38 const req = httpTesting.expectOne('api/cluster_conf/configOption');
39 expect(req.request.method).toBe('GET');
40 });
41
42 it('should call create', () => {
43 const configOption = new ConfigFormCreateRequestModel();
44 configOption.name = 'Test option';
45 configOption.value = [
46 { section: 'section1', value: 'value1' },
47 { section: 'section2', value: 'value2' }
48 ];
49 service.create(configOption).subscribe();
50 const req = httpTesting.expectOne('api/cluster_conf/');
51 expect(req.request.method).toBe('POST');
52 expect(req.request.body).toEqual(configOption);
53 });
81eedcae
TL
54
55 it('should call bulkCreate', () => {
56 const configOptions = {
57 configOption1: { section: 'section', value: 'value' },
58 configOption2: { section: 'section', value: 'value' }
59 };
60 service.bulkCreate(configOptions).subscribe();
61 const req = httpTesting.expectOne('api/cluster_conf/');
62 expect(req.request.method).toBe('PUT');
63 expect(req.request.body).toEqual(configOptions);
64 });
65
66 it('should call filter', () => {
67 const configOptions = ['configOption1', 'configOption2', 'configOption3'];
68 service.filter(configOptions).subscribe();
69 const req = httpTesting.expectOne(
70 'api/cluster_conf/filter?names=configOption1,configOption2,configOption3'
71 );
72 expect(req.request.method).toBe('GET');
73 });
74
75 it('should call delete', () => {
76 service.delete('testOption', 'testSection').subscribe();
77 const reg = httpTesting.expectOne('api/cluster_conf/testOption?section=testSection');
78 expect(reg.request.method).toBe('DELETE');
79 });
11fdf7f2 80});