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    
@doodle/proxy / src / proxy.spec.js
Size: Mime:
const FAKE_PATH = 'myFavouritePath';

jest.mock('request', () =>
  jest.fn().mockReturnValue({
    on: jest.fn().mockReturnValue({
      pipe: jest.fn(),
    }),
  })
);
jest.mock('url', () => ({
  parse: jest.fn().mockReturnValue({ path: FAKE_PATH }),
}));

const request = require('request');
const url = require('url');
const proxy = require('./proxy');

describe('Proxy module', () => {
  it('should change the host of the request and pipe the result of the new request back', () => {
    const target = 'https://awesomeness.dud3l.com/';
    const req = {
      body: {
        bestProp: 'J',
      },
      method: 'POSTALKOMBAT',
      headers: {
        'content-type': 'application/json',
        host: 'not-the-best-host',
        origin: 'far,far away...',
      },
      originalUrl: 'https://the-wurst-host',
    };
    const res = {};
    proxy(target)(req, res);
    expect(request).toHaveBeenCalledWith({
      url: `${target}${FAKE_PATH}`,
      headers: { 'content-type': 'application/json' },
      method: req.method,
      body: JSON.stringify(req.body),
      encoding: undefined,
    });
  });
});