11import {
22 getCleanBalancerValue ,
33 parseBalancer ,
4+ prepareBackendFromBalancer ,
45 removePort ,
56 removeProtocol ,
67 removeViewerPathname ,
@@ -68,12 +69,17 @@ describe('removeViewerPathname', () => {
6869 } ) ;
6970} ) ;
7071describe ( 'removeProtocol' , ( ) => {
71- test ( 'should remove protocol' , ( ) => {
72+ test ( 'should remove protocol from start ' , ( ) => {
7273 const initialValue = 'https://ydb-testing-0000.search.net:8765/viewer/json' ;
7374 const result = 'ydb-testing-0000.search.net:8765/viewer/json' ;
7475
7576 expect ( removeProtocol ( initialValue ) ) . toBe ( result ) ;
7677 } ) ;
78+ test ( 'should not remove protocol string in the middle' , ( ) => {
79+ const initialValue = 'proxy/host/https:ydb-testing-0000.search.net' ;
80+
81+ expect ( removeProtocol ( initialValue ) ) . toBe ( initialValue ) ;
82+ } ) ;
7783} ) ;
7884describe ( 'removePort' , ( ) => {
7985 test ( 'should remove port' , ( ) => {
@@ -92,3 +98,69 @@ describe('getCleanBalancerValue', () => {
9298 expect ( getCleanBalancerValue ( initialValue ) ) . toBe ( result ) ;
9399 } ) ;
94100} ) ;
101+ describe ( 'prepareBackendFromBalancer' , ( ) => {
102+ const windowSpy = jest . spyOn ( window , 'window' , 'get' ) ;
103+
104+ afterEach ( ( ) => {
105+ windowSpy . mockClear ( ) ;
106+ } ) ;
107+ afterAll ( ( ) => {
108+ windowSpy . mockRestore ( ) ;
109+ } ) ;
110+
111+ test ( 'should not change full balancer value - only remove viewer pathname' , ( ) => {
112+ const initialValue = 'https://ydb-testing-0000.search.net:8765/viewer/json' ;
113+ const result = 'https://ydb-testing-0000.search.net:8765' ;
114+
115+ expect ( prepareBackendFromBalancer ( initialValue ) ) . toBe ( result ) ;
116+ } ) ;
117+
118+ test ( 'should add meta backend for relative balancer value' , ( ) => {
119+ const initialValue = '/proxy/host/ydb-testing-0000.search.net/viewer/json' ;
120+ const result = 'https://my-host.ru/proxy/host/ydb-testing-0000.search.net' ;
121+
122+ windowSpy . mockImplementation ( ( ) => {
123+ return {
124+ meta_backend : 'https://my-host.ru' ,
125+ } as Window & typeof globalThis ;
126+ } ) ;
127+
128+ expect ( prepareBackendFromBalancer ( initialValue ) ) . toBe ( result ) ;
129+ } ) ;
130+ test ( 'should add relative meta backend for relative balancer value' , ( ) => {
131+ const initialValue = '/proxy/host/ydb-testing-0000.search.net/viewer/json' ;
132+ const result = '/meta/proxy/host/ydb-testing-0000.search.net' ;
133+
134+ windowSpy . mockImplementation ( ( ) => {
135+ return {
136+ meta_backend : '/meta' ,
137+ } as Window & typeof globalThis ;
138+ } ) ;
139+
140+ expect ( prepareBackendFromBalancer ( initialValue ) ) . toBe ( result ) ;
141+ } ) ;
142+ test ( 'should not add empty meta backend for relative balancer value' , ( ) => {
143+ const initialValue = '/proxy/host/ydb-testing-0000.search.net/viewer/json' ;
144+ const result = '/proxy/host/ydb-testing-0000.search.net' ;
145+
146+ windowSpy . mockImplementation ( ( ) => {
147+ return {
148+ meta_backend : '' ,
149+ } as Window & typeof globalThis ;
150+ } ) ;
151+
152+ expect ( prepareBackendFromBalancer ( initialValue ) ) . toBe ( result ) ;
153+ } ) ;
154+ test ( 'should not add undefined meta backend for relative balancer value' , ( ) => {
155+ const initialValue = '/proxy/host/ydb-testing-0000.search.net/viewer/json' ;
156+ const result = '/proxy/host/ydb-testing-0000.search.net' ;
157+
158+ windowSpy . mockImplementation ( ( ) => {
159+ return {
160+ meta_backend : undefined ,
161+ } as Window & typeof globalThis ;
162+ } ) ;
163+
164+ expect ( prepareBackendFromBalancer ( initialValue ) ) . toBe ( result ) ;
165+ } ) ;
166+ } ) ;
0 commit comments