diff --git a/docs/02_concepts/04_proxy_management.mdx b/docs/02_concepts/04_proxy_management.mdx index 8f35ccf692..8a666cbadd 100644 --- a/docs/02_concepts/04_proxy_management.mdx +++ b/docs/02_concepts/04_proxy_management.mdx @@ -142,20 +142,18 @@ The difference is easy to remember. { expect(proxyConfiguration.countryCode).toStrictEqual(apifyProxyCountry); }); + test('subdivisionCode should produce country-US_XX in proxy URL', async () => { + const proxyConfiguration = new ProxyConfiguration({ + groups, + countryCode: 'US', + subdivisionCode: 'CA', + password, + }); + + expect(await proxyConfiguration.newUrl(sessionId)).toBe( + 'http://groups-GROUP1+GROUP2,session-538909250932,country-US_CA:test12345@proxy.apify.com:8000', + ); + }); + + test('subdivisionCode without session should produce correct URL', async () => { + const proxyConfiguration = new ProxyConfiguration({ + groups, + countryCode: 'US', + subdivisionCode: 'NY', + password, + }); + + expect(await proxyConfiguration.newUrl()).toBe( + 'http://groups-GROUP1+GROUP2,country-US_NY:test12345@proxy.apify.com:8000', + ); + }); + + test('apifyProxySubdivision UI input schema should work', async () => { + const proxyConfiguration = new ProxyConfiguration({ + apifyProxyGroups: groups, + apifyProxyCountry: 'US', + apifyProxySubdivision: 'TX', + password, + }); + + // @ts-expect-error private property + expect(proxyConfiguration.subdivisionCode).toBe('TX'); + expect(await proxyConfiguration.newUrl()).toBe( + 'http://groups-GROUP1+GROUP2,country-US_TX:test12345@proxy.apify.com:8000', + ); + }); + + test('subdivisionCode without countryCode should throw', () => { + expect( + () => new ProxyConfiguration({ subdivisionCode: 'CA', password }), + ).toThrow( + 'ProxyConfiguration: "subdivisionCode" requires "countryCode" to be set.', + ); + expect( + () => + new ProxyConfiguration({ + apifyProxySubdivision: 'CA', + password, + }), + ).toThrow( + 'ProxyConfiguration: "subdivisionCode" requires "countryCode" to be set.', + ); + }); + + test('should throw on invalid subdivisionCode', () => { + expect( + () => + new ProxyConfiguration({ + countryCode: 'US', + subdivisionCode: 'ca', + password, + }), + ).toThrow(); + expect( + () => + new ProxyConfiguration({ + countryCode: 'US', + subdivisionCode: 'California', + password, + }), + ).toThrow(); + }); + test('should throw on invalid arguments structure', () => { // Group value const invalidGroups = ['GROUP1*'];