1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { ConfigFormCreateRequestModel } from '../../ceph/cluster/configuration/configuration-form/configuration-form-create-request.model';
6 import { ConfigurationService } from './configuration.service';
8 describe('ConfigurationService', () => {
9 let service: ConfigurationService;
10 let httpTesting: HttpTestingController;
13 providers: [ConfigurationService],
14 imports: [HttpClientTestingModule]
18 service = TestBed.get(ConfigurationService);
19 httpTesting = TestBed.get(HttpTestingController);
26 it('should be created', () => {
27 expect(service).toBeTruthy();
30 it('should call getConfigData', () => {
31 service.getConfigData().subscribe();
32 const req = httpTesting.expectOne('api/cluster_conf/');
33 expect(req.request.method).toBe('GET');
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');
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' }
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);
55 it('should call bulkCreate', () => {
56 const configOptions = {
57 configOption1: { section: 'section', value: 'value' },
58 configOption2: { section: 'section', value: 'value' }
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);
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'
72 expect(req.request.method).toBe('GET');
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');
81 it('should get value', () => {
85 { section: 'global', value: 'b' },
86 { section: 'mon', value: 'c' },
87 { section: 'mon.1', value: 'd' },
88 { section: 'mds', value: 'e' }
91 expect(service.getValue(config, 'mon.1')).toBe('d');
92 expect(service.getValue(config, 'mon')).toBe('c');
93 expect(service.getValue(config, 'mds.1')).toBe('e');
94 expect(service.getValue(config, 'mds')).toBe('e');
95 expect(service.getValue(config, 'osd')).toBe('b');
97 expect(service.getValue(config, 'osd')).toBe('a');