1
1
import {
2
2
getCleanBalancerValue ,
3
3
parseBalancer ,
4
+ prepareBackendFromBalancer ,
4
5
removePort ,
5
6
removeProtocol ,
6
7
removeViewerPathname ,
@@ -68,12 +69,17 @@ describe('removeViewerPathname', () => {
68
69
} ) ;
69
70
} ) ;
70
71
describe ( 'removeProtocol' , ( ) => {
71
- test ( 'should remove protocol' , ( ) => {
72
+ test ( 'should remove protocol from start ' , ( ) => {
72
73
const initialValue = 'https://ydb-testing-0000.search.net:8765/viewer/json' ;
73
74
const result = 'ydb-testing-0000.search.net:8765/viewer/json' ;
74
75
75
76
expect ( removeProtocol ( initialValue ) ) . toBe ( result ) ;
76
77
} ) ;
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
+ } ) ;
77
83
} ) ;
78
84
describe ( 'removePort' , ( ) => {
79
85
test ( 'should remove port' , ( ) => {
@@ -92,3 +98,69 @@ describe('getCleanBalancerValue', () => {
92
98
expect ( getCleanBalancerValue ( initialValue ) ) . toBe ( result ) ;
93
99
} ) ;
94
100
} ) ;
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