{"size": 1088, "ext": "js", "max_stars_repo_path": "packages/core/resolve-redux/test/get_root_based_url.test.js", "max_stars_repo_name": "artemjackson/resolve", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/core/resolve-redux/test/get_root_based_url.test.js", "max_issues_repo_name": "artemjackson/resolve", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/core/resolve-redux/test/get_root_based_url.test.js", "max_forks_repo_name": "artemjackson/resolve", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1489361702, "max_line_length": 79, "alphanum_fraction": 0.5790441176}
import sinon from 'sinon'

import getRootBasedUrl from '../src/get_root_based_url'

describe('getRootBasedUrl', () => {
  let sandbox

  beforeAll(() => {
    sandbox = sinon.createSandbox()
    sandbox.stub(console, 'error')
  })

  afterAll(() => {
    sandbox.restore()
  })

  test('should return root based URL', () => {
    expect(
      getRootBasedUrl('http://localhost:3000', 'my-app', '/api/query')
    ).toEqual('http://localhost:3000/my-app/api/query')
  })

  test('should return normal URL', () => {
    expect(getRootBasedUrl('http://localhost:3000', '', '/api/query')).toEqual(
      'http://localhost:3000/api/query'
    )
  })

  test('should return absolute URL', () => {
    expect(
      getRootBasedUrl(
        'http://localhost:3000',
        '',
        'https://localhost:3001/api/query'
      )
    ).toEqual('https://localhost:3001/api/query')
  })

  test('should fail', () => {
    expect(() =>
      getRootBasedUrl('http://localhost:3000', 'my-app', '')
    ).toThrow()

    expect(() => getRootBasedUrl('http://localhost:3000', '', '')).toThrow()
  })
})
