@@ -58,6 +58,18 @@ test('setting log tag', () => {
5858 expect ( builder [ "logTag" ] ) . toBe ( logTag ) ;
5959} ) ;
6060
61+ test ( 'setting api url' , ( ) => {
62+ // given
63+ const builder = new QonversionConfigBuilder ( 'test' ) ;
64+ const apiUrl = 'https://proxy.example.com' ;
65+
66+ // when
67+ builder . setApiUrl ( apiUrl ) ;
68+
69+ // then
70+ expect ( builder [ "apiUrl" ] ) . toBe ( apiUrl ) ;
71+ } ) ;
72+
6173test ( 'successful build with full list of arguments' , ( ) => {
6274 // given
6375 const mockLogLevel = LogLevel . Warning ;
@@ -132,6 +144,36 @@ test('successful build without full list of arguments', () => {
132144 expect ( result ) . toStrictEqual ( expResult ) ;
133145} ) ;
134146
147+ test ( 'successful build with custom api url' , ( ) => {
148+ // given
149+ const projectKey = "test key" ;
150+ const apiUrl = 'https://proxy.example.com' ;
151+
152+ const builder = new QonversionConfigBuilder ( projectKey ) ;
153+ builder . setApiUrl ( apiUrl ) ;
154+
155+ // when
156+ const result = builder . build ( )
157+
158+ // then
159+ expect ( result . networkConfig . apiUrl ) . toBe ( apiUrl ) ;
160+ } ) ;
161+
162+ test ( 'normalizes custom api url by removing trailing slash' , ( ) => {
163+ // given
164+ const projectKey = "test key" ;
165+ const apiUrl = 'https://proxy.example.com/' ;
166+
167+ const builder = new QonversionConfigBuilder ( projectKey ) ;
168+ builder . setApiUrl ( apiUrl ) ;
169+
170+ // when
171+ const result = builder . build ( )
172+
173+ // then
174+ expect ( result . networkConfig . apiUrl ) . toBe ( 'https://proxy.example.com' ) ;
175+ } ) ;
176+
135177test ( 'building with blank project key' , ( ) => {
136178 // given
137179 const builder = new QonversionConfigBuilder ( "" ) ;
@@ -140,3 +182,30 @@ test('building with blank project key', () => {
140182 // when and then
141183 expectQonversionError ( QonversionErrorCode . ConfigPreparation , testingMethod ) ;
142184} ) ;
185+
186+ test ( 'building with blank api url throws' , ( ) => {
187+ // given
188+ const builder = new QonversionConfigBuilder ( "test" ) ;
189+ const testingMethod = ( ) => builder . setApiUrl ( "" ) ;
190+
191+ // when and then
192+ expectQonversionError ( QonversionErrorCode . ConfigPreparation , testingMethod ) ;
193+ } ) ;
194+
195+ test ( 'building with invalid api url throws' , ( ) => {
196+ // given
197+ const builder = new QonversionConfigBuilder ( "test" ) ;
198+ const testingMethod = ( ) => builder . setApiUrl ( "not a url" ) ;
199+
200+ // when and then
201+ expectQonversionError ( QonversionErrorCode . ConfigPreparation , testingMethod ) ;
202+ } ) ;
203+
204+ test ( 'building with non-https api url throws' , ( ) => {
205+ // given
206+ const builder = new QonversionConfigBuilder ( "test" ) ;
207+ const testingMethod = ( ) => builder . setApiUrl ( "http://proxy.example.com" ) ;
208+
209+ // when and then
210+ expectQonversionError ( QonversionErrorCode . ConfigPreparation , testingMethod ) ;
211+ } ) ;
0 commit comments