]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
85b1b1b00fa4385a34bdc481b6a8d036d62950ec
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { RgwTopicDetailsComponent } from './rgw-topic-details.component';
3 import { TopicDetails } from '~/app/shared/models/topic.model';
4
5 interface Destination {
6   push_endpoint: string;
7   push_endpoint_args: string;
8   push_endpoint_topic: string;
9   stored_secret: string;
10   persistent: boolean;
11   persistent_queue: string;
12   time_to_live: number;
13   max_retries: number;
14   retry_sleep_duration: number;
15 }
16
17 const mockDestination: Destination = {
18   push_endpoint: 'http://localhost:8080',
19   push_endpoint_args: 'args',
20   push_endpoint_topic: 'topic',
21   stored_secret: 'secret',
22   persistent: true,
23   persistent_queue: 'queue',
24   time_to_live: 3600,
25   max_retries: 5,
26   retry_sleep_duration: 10
27 };
28
29 describe('RgwTopicDetailsComponent', () => {
30   let component: RgwTopicDetailsComponent;
31   let fixture: ComponentFixture<RgwTopicDetailsComponent>;
32
33   beforeEach(async () => {
34     await TestBed.configureTestingModule({
35       declarations: [RgwTopicDetailsComponent]
36     }).compileComponents();
37
38     fixture = TestBed.createComponent(RgwTopicDetailsComponent);
39     component = fixture.componentInstance;
40     fixture.detectChanges();
41   });
42
43   it('should create', () => {
44     expect(component).toBeTruthy();
45   });
46
47   it('should parse policy string correctly', () => {
48     const mockSelection: TopicDetails = {
49       name: 'testHttp',
50       owner: 'ownerName',
51       arn: 'arnValue',
52       dest: mockDestination,
53       policy: '{"key": "value"}',
54       opaqueData: 'test@12345',
55       subscribed_buckets: []
56     };
57
58     component.selection = mockSelection;
59     component.ngOnChanges({
60       selection: {
61         currentValue: mockSelection,
62         previousValue: null,
63         firstChange: true,
64         isFirstChange: () => true
65       }
66     });
67
68     expect(component.policy).toEqual({ key: 'value' });
69   });
70
71   it('should set policy to empty object if policy is not a string', () => {
72     const mockSelection: TopicDetails = {
73       name: 'testHttp',
74       owner: 'ownerName',
75       arn: 'arnValue',
76       dest: mockDestination,
77       policy: '{}',
78       subscribed_buckets: [],
79       opaqueData: ''
80     };
81
82     component.selection = mockSelection;
83     component.ngOnChanges({
84       selection: {
85         currentValue: mockSelection,
86         previousValue: null,
87         firstChange: true,
88         isFirstChange: () => true
89       }
90     });
91
92     expect(component.policy).toEqual({});
93   });
94 });