{"size": 1526, "ext": "js", "max_stars_repo_path": "macros/remove-local-routes/test.js", "max_stars_repo_name": "herschel666/arc-macros", "max_stars_repo_stars_event_min_datetime": "2021-06-20T01:20:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-20T01:20:34.000Z", "max_issues_repo_path": "macros/remove-local-routes/test.js", "max_issues_repo_name": "herschel666/arc-macros", "max_issues_repo_issues_event_min_datetime": "2020-06-13T13:19:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T16:29:00.000Z", "max_forks_repo_path": "macros/remove-local-routes/test.js", "max_forks_repo_name": "herschel666/arc-macros", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 21.1944444444, "max_line_length": 80, "alphanum_fraction": 0.6730013106}
const test = require('ava');
const inventory = require('@architect/inventory');
const toServerlessCloudFormation = require('@architect/package');

const macro = require('.');

const otherArcRaw = `
@app
test
`;

const arcRaw = `
@app
test

@http
get /
get /api/:foo
get /foo/:bar
post /foo/:bar
get /foo/lorem
put /some/:other/route/:with/:params

@macros
herschel666-arc-macros-remove-local-routes

@herschel666-arc-macros-remove-local-routes
/foo/:bar
/foo/lorem
/some/:other/route/:with/:params
`;

const arcToBe = `
@app
test

@http
get /
get /api/:foo
`;

const getOtherArc = async () => inventory({ rawArc: otherArcRaw });

const getArc = async () => {
  const { inv } = await inventory({ rawArc: arcRaw });
  const cfn = toServerlessCloudFormation({ inv });
  return { arc: inv._project.arc, cfn };
};

const getCfnToBe = async () => {
  const { inv } = await inventory({ rawArc: arcToBe });
  // eslint-disable-next-line no-unused-vars
  const { Description, ...cfnToBe } = toServerlessCloudFormation({ inv });
  return cfnToBe;
};

test('Ignore Cloudformation template when macro is not included', async (t) => {
  t.plan(1);
  const cfn = {};
  const result = macro(await getOtherArc(), cfn);
  t.is(result, cfn);
});

test('Removing the routes from Cloudformation template', async (t) => {
  t.plan(1);
  const { arc, cfn } = await getArc();
  const cfnToBe = await getCfnToBe();
  // eslint-disable-next-line no-unused-vars
  const { Description, ...result } = macro(arc, cfn);
  t.deepEqual(result, cfnToBe);
});
