Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
// @todo supertest
function toMock() {
  let { url, params, data, method } = this.store
  // eslint-disable-next-line
  const nock = require('nock')
  const mockUrl = 'http://localhost:3000'
  // console.log('mock data', this.store)
  // @NOTE naming it apiUrl was better, oops
  // show helpful messages to make sure people use it
  this.validateRequestStore()
  // for now, autofix it to include the baseUrl
  if (!url.includes('http')) {
    url = mockUrl + url
  }
  const handleGet = urlRequested => {
    // `api/${url}`
    const doesRequestIncludeUrl =
      urlRequested.includes(url) || url.includes(urlRequested)
    // this.log('getCall', { url, urlRequested, doesRequestIncludeUrl })
    return doesRequestIncludeUrl
  }
  if (this.isPost) {
    // console.dev(`${this.store.method} MOCKED`)
    return nock(mockUrl).post(url).query(params).reply(201, data)
  } else {
    // console.dev(`${url} GET Crocked`)
    return nock(mockUrl).get(handleGet).query(params).reply(200, data)
  }
}

export { toMock }