{"size": 1402, "ext": "js", "max_stars_repo_path": "lib/report.js", "max_stars_repo_name": "mafischer/raml-api-tester", "max_stars_repo_stars_event_min_datetime": "2022-03-03T19:38:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T19:38:49.000Z", "max_issues_repo_path": "lib/report.js", "max_issues_repo_name": "mafischer/raml-api-tester", "max_issues_repo_issues_event_min_datetime": "2018-06-18T21:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-14T14:49:11.000Z", "max_forks_repo_path": "lib/report.js", "max_forks_repo_name": "mafischer/raml-api-tester", "max_forks_repo_forks_event_min_datetime": "2020-07-31T16:53:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-31T16:53:46.000Z"}
{"max_stars_count": 1, "max_issues_count": 12, "max_forks_count": 1, "avg_line_length": 35.05, "max_line_length": 151, "alphanum_fraction": 0.5813124108}
const Mocha = require('mocha');
const expect = require('chai').expect;

module.exports = function(results){
    const mocha = new Mocha({
        reporter: 'spec'
    });
    const rat = {
        root: Mocha.Suite.create(mocha.suite, 'RAML API Tester')
    };

    report(rat, results);

    mocha.run();

    console.log("Testing is now complete!");

};

const report = (rat, results) => {
    let message;
    Object.keys(results).forEach(function(resource){
        if(!results[resource].hasOwnProperty('err')){
            report(rat, results[resource]);
        } else {
            if(results[resource].request && results[resource].request.uri.path) {
                if (!rat.hasOwnProperty(results[resource].request.path)) {
                    rat[results[resource].request.uri.path] = Mocha.Suite.create(rat[resource.parent] || rat.root, results[resource].request.uri.path);
                }
                rat[results[resource].request.uri.path].addTest(new Mocha.Test(results[resource].request.method + " should return 2xx", function () {
                    message = JSON.stringify(results[resource], null, 2);
                    expect(results[resource].response.statusCode, message).to.be.within(200, 299);
                }));
            } else {
                console.error("Missing response data for: " + JSON.stringify(results[resource]));
            }
        }
    });
};
