{"size": 1360, "ext": "js", "max_stars_repo_path": "modules/gateway/docker/src/rewrite.test.js", "max_stars_repo_name": "openforis/sepal", "max_stars_repo_stars_event_min_datetime": "2015-10-23T09:00:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T03:24:04.000Z", "max_issues_repo_path": "modules/gateway/docker/src/rewrite.test.js", "max_issues_repo_name": "openforis/sepal", "max_issues_repo_issues_event_min_datetime": "2015-09-24T09:53:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T09:55:06.000Z", "max_forks_repo_path": "modules/gateway/docker/src/rewrite.test.js", "max_forks_repo_name": "openforis/sepal", "max_forks_repo_forks_event_min_datetime": "2016-07-10T10:40:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-14T01:07:33.000Z"}
{"max_stars_count": 153, "max_issues_count": 165, "max_forks_count": 46, "avg_line_length": 24.2857142857, "max_line_length": 53, "alphanum_fraction": 0.5316176471}
const {rewriteLocation} = require('./rewrite')
test('root of target', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234',
        location: '/c/d'
    })
    expect(rewritten).toBe('/a/b/c/d')
})

test('same target and location path', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234/c/d',
        location: '/c/d'
    })
    expect(rewritten).toBe('/a/b')
})

test('deep location path', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234/c/d',
        location: '/c/d/e/f'
    })
    expect(rewritten).toBe('/a/b/e/f')
})

test('location path outside of target', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234/c/d',
        location: '/e/f'
    })
    expect(rewritten).toBe('/a/b/e/f')
})

test('location at root', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234',
        location: '/'
    })
    expect(rewritten).toBe('/a/b')
})

test('different host', () => {
    const rewritten = rewriteLocation({
        path: '/a/b',
        target: 'http://domain:1234',
        location: 'http://another:1234/c/d'
    })
    expect(rewritten).toBe('http://another:1234/c/d')
})

