]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
4c7e3d6c3f0f91bbaa80e772b0eec839826389fe
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ReactiveFormsModule } from '@angular/forms';
3 import { RouterTestingModule } from '@angular/router/testing';
4 import { ComponentFixture, TestBed } from '@angular/core/testing';
5
6 import { ToastrModule } from 'ngx-toastr';
7
8 import { NgbActiveModal, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
9
10 import { SharedModule } from '~/app/shared/shared.module';
11 import {
12   NvmeofSubsystemsFormComponent,
13   SubsystemPayload
14 } from './nvmeof-subsystems-form.component';
15 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
16 import { NvmeofSubsystemsStepOneComponent } from './nvmeof-subsystem-step-1/nvmeof-subsystem-step-1.component';
17 import { GridModule, InputModule, RadioModule, TagModule } from 'carbon-components-angular';
18 import { NvmeofSubsystemsStepThreeComponent } from './nvmeof-subsystem-step-3/nvmeof-subsystem-step-3.component';
19 import { HOST_TYPE } from '~/app/shared/models/nvmeof';
20 import { NvmeofSubsystemsStepTwoComponent } from './nvmeof-subsystem-step-2/nvmeof-subsystem-step-2.component';
21 import { of } from 'rxjs';
22
23 describe('NvmeofSubsystemsFormComponent', () => {
24   let component: NvmeofSubsystemsFormComponent;
25   let fixture: ComponentFixture<NvmeofSubsystemsFormComponent>;
26   let nvmeofService: NvmeofService;
27   const mockTimestamp = 1720693470789;
28   const mockGroupName = 'default';
29   const mockPayload: SubsystemPayload = {
30     nqn: '',
31     gw_group: mockGroupName,
32     subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY=',
33     addedHosts: [],
34     hostType: HOST_TYPE.ALL
35   };
36
37   beforeEach(async () => {
38     spyOn(Date, 'now').and.returnValue(mockTimestamp);
39     await TestBed.configureTestingModule({
40       declarations: [
41         NvmeofSubsystemsFormComponent,
42         NvmeofSubsystemsStepOneComponent,
43         NvmeofSubsystemsStepThreeComponent,
44         NvmeofSubsystemsStepTwoComponent
45       ],
46       providers: [NgbActiveModal],
47       imports: [
48         HttpClientTestingModule,
49         NgbTypeaheadModule,
50         ReactiveFormsModule,
51         RouterTestingModule,
52         SharedModule,
53         InputModule,
54         GridModule,
55         RadioModule,
56         TagModule,
57         ToastrModule.forRoot()
58       ]
59     }).compileComponents();
60
61     fixture = TestBed.createComponent(NvmeofSubsystemsFormComponent);
62     component = fixture.componentInstance;
63     component.ngOnInit();
64     fixture.detectChanges();
65     component.group = mockGroupName;
66   });
67
68   it('should create', () => {
69     expect(component).toBeTruthy();
70   });
71
72   describe('should test form', () => {
73     beforeEach(() => {
74       nvmeofService = TestBed.inject(NvmeofService);
75       spyOn(nvmeofService, 'createSubsystem').and.returnValue(of({}));
76       spyOn(nvmeofService, 'addInitiators').and.returnValue(of({}));
77     });
78
79     it('should be creating request correctly', () => {
80       const expectedNqn = 'nqn.2001-07.com.ceph:' + mockTimestamp;
81       mockPayload['nqn'] = expectedNqn;
82       component.onSubmit(mockPayload);
83       expect(nvmeofService.createSubsystem).toHaveBeenCalledWith({
84         nqn: expectedNqn,
85         gw_group: mockGroupName,
86         enable_ha: true,
87         dhchap_key: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
88       });
89     });
90
91     it('should add initiators with wildcard when hostType is ALL', () => {
92       const payload: SubsystemPayload = {
93         nqn: 'test-nqn',
94         gw_group: mockGroupName,
95         addedHosts: [],
96         hostType: HOST_TYPE.ALL,
97         subsystemDchapKey: 'Q2VwaE52bWVvRkNoYXBTeW50aGV0aWNLZXkxMjM0NTY='
98       };
99
100       component.group = mockGroupName;
101       component.onSubmit(payload);
102
103       expect(nvmeofService.addInitiators).toHaveBeenCalledWith('test-nqn.default', {
104         host_nqn: '*',
105         gw_group: mockGroupName
106       });
107     });
108   });
109 });