Since data returned from the Google API can rely on actual live campaigns, the purpose of this proxy is to mock some of that data.
Prerequisites:
npm install
npm run test-proxy
Or, if you want to use a local connect server:
WOOCOMMERCE_CONNECT_SERVER=http://localhost:5500 npm run test-proxy
To run the proxy using a custom host you can start it as follows:
PROXY_HOST='127.0.0.1' npm run test-proxy
To run the proxy using a custom port you can start it as follows:
PROXY_PORT=50505 npm run test-proxy
The mode will determine what kind of responses will be returned, this is used to mock specific responses which can't be reproduced through regular requests.
Modes:
access_errorwill return a 403 error when getting market insights data (i.e. price benchmarks)delete_errorwill return an internal error when deleting productsupdate_errorwill return an internal error when updating products
PROXY_MODE=<access_error|delete_error|update_error> npm run test-proxy
This option will allow us to view the responses which are returned from the API, this is useful for generating mocked responses to return.
PROXY_LOG_RESPONSES=true npm run test-proxy
On your test site you will need to run a PHP snippet to use the proxy to handle any requests:
define( 'WOOCOMMERCE_GLA_CONNECT_SERVER_URL', 'http://localhost:5555' );Or, if your test site is running within a docker container, the PHP snippet would be the following instead:
define( 'WOOCOMMERCE_GLA_CONNECT_SERVER_URL', 'http://host.docker.internal:5555' );host.docker.internal works only on Mac environments. On others, you would have to use 172.17.0.1 instead of localhost in the PHP snippet and in tests/proxy/config.js.
At the moment only the report data is mocked, the rest of the requests are sent on to the connect server. The mocks folder contains example responses for the reports.