// ui-test env hack
const { URL } = require('url');
const getEnv = require('./getEnv');

module.exports = (req, url) => {
    let urlObject = url instanceof URL ? url : new URL(url);

    if (getEnv(req) === 'ui-test') {
        let { cookies } = req;

        if (cookies['dumps-test-path']) {
            urlObject.searchParams.set('dumps-test-path', cookies['dumps-test-path']);
        }

        if (cookies.__hash__) {
            urlObject.searchParams.set('__hash__', cookies.__hash__);
        }
    }

    return urlObject;
};
