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:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toMock = toMock;

// @todo supertest
function toMock() {
  let _store = this.store,
      url = _store.url,
      params = _store.params,
      data = _store.data,
      method = _store.method; // 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);
  }
}