{"size": 1541, "ext": "js", "max_stars_repo_path": "providers/mobike/tests/index.js", "max_stars_repo_name": "douglasduteil/multicycles", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "providers/mobike/tests/index.js", "max_issues_repo_name": "douglasduteil/multicycles", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "providers/mobike/tests/index.js", "max_forks_repo_name": "douglasduteil/multicycles", "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": 17.9186046512, "max_line_length": 53, "alphanum_fraction": 0.5055158988}
import test from 'ava'
import nock from 'nock'
import Mobike from '../lib'

nock('https://mwx.mobike.com/mobike-api')
  .post('/rent/nearbyBikesInfo.do', {
    latitude: 31.23039,
    longitude: 121.473702
  })
  .reply(200, {
    code: 0,
    message: '',
    biketype: 0,
    autoZoom: true,
    radius: 150,
    object: [
      {
        distId: '0216729683',
        distX: 121.47473058,
        distY: 31.23069014,
        distNum: 1,
        distance: '103',
        bikeIds: '0216729683#',
        biketype: 1,
        type: 0,
        boundary: null
      }
    ]
  })

test('overwrite timeout on constructor', async t => {
  const mobike = new Mobike({ timeout: 1 })

  await mobike
    .getObjects({
      lat: 38.907192,
      lng: -77.036871
    })
    .then(() => {
      t.fail()
    })
    .catch(err => {
      t.is(err.code, 'ETIMEDOUT')
      t.pass()
    })
})

test('overwrite timeout on method', async t => {
  const mobike = new Mobike()

  await mobike
    .getObjects(
      {
        lat: 38.907192,
        lng: -77.036871
      },
      { timeout: 1 }
    )
    .then(() => {
      t.fail()
    })
    .catch(err => {
      t.is(err.code, 'ETIMEDOUT')
      t.pass()
    })
})

test('get objects', async t => {
  const mobike = new Mobike()

  await mobike
    .getObjects({
      lat: 31.23039,
      lng: 121.473702
    })
    .then(result => {
      t.is(result.statusCode, 200)
      t.truthy(result.body.object.length)
      t.pass()
    })
    .catch(err => {
      console.log(err)
      t.fail()
    })
})
