{"size": 1415, "ext": "js", "max_stars_repo_path": "test/test_async-util.js", "max_stars_repo_name": "Zenith00/swaps-service", "max_stars_repo_stars_event_min_datetime": "2018-04-09T06:27:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-05T14:55:57.000Z", "max_issues_repo_path": "test/test_async-util.js", "max_issues_repo_name": "Zenith00/swaps-service", "max_issues_repo_issues_event_min_datetime": "2018-04-07T04:43:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-09T00:13:17.000Z", "max_forks_repo_path": "test/test_async-util.js", "max_forks_repo_name": "Zenith00/swaps-service", "max_forks_repo_forks_event_min_datetime": "2018-06-10T15:08:00.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-29T23:21:03.000Z"}
{"max_stars_count": 16, "max_issues_count": 14, "max_forks_count": 2, "avg_line_length": 20.5072463768, "max_line_length": 63, "alphanum_fraction": 0.5978798587}
const {log} = console;

const {test} = require('tap');

const {returnJson} = require('./../async-util');
const {returnResult} = require('./../async-util');

// returnJson: Test sending normal JSON
test('normal json is sent', t => {
  const log = msg => t.fail();
  const fixture = {foo: 'bar'};

  const json = ({foo}) => t.equal(foo, fixture.foo) && t.end();

  const res = {json};

  return returnJson({log, res})(null, fixture);
});

// returnJson: Test sending errors
test('error is sent', t => {
  const fixture = [500, 'ServerError'];

  const res = {};

  const status = code => {
    t.equal(code, fixture[0]);

    return res;
  };

  const log = msg => t.equal(msg, fixture);
  const send = msg => t.equal(msg, fixture[1]) && t.end();

  res.send = send;
  res.status = status;

  return returnJson({log, res})(fixture);
});

// returnResult: Test returning the result of an asyncAuto
test('result is returned in isolation', t => {
  const fixture = {baz: 1, foo: 'bar'};

  const cbk = (err, res) => {
    t.equal(err, null);
    t.equal(res, fixture.foo);
    t.equal(res.baz, undefined);

    t.end();
  };

  return returnResult({of: 'foo'}, cbk)(null, fixture);
});

// returnResult: Test returning errors
test('error is passed along', t => {
  const fixture = 'ServerError';

  const cbk = (err, res) => {
    t.equal(err, fixture);

    t.end();
  };

  return returnResult({}, cbk)(fixture);
});

