async function handleGetTestResults()

in app.js [95:121]


async function handleGetTestResults(request, response, next) {
    const runId = request.params.runId;
    const activeRunIds = ResultsManager.getActiveRunIds();
    if (!activeRunIds.has(runId)) { // If runId doesn't exist (either deleted or never existed)
        response.setHeader("content-type", "application/json");
        response.send(404, {results: [], errorMessage:"RunId does not exist.", verdict:"error"});
        return;
    }
    // Else, runId exists.
    const resultsObject = ResultsManager.getSuiteResults(runId);
    if (!resultsObject) { // If results are not ready
        response.setHeader("content-type", "application/json");
        response.setHeader("Location", "http://" + request.headers.host + "/getResults/" + runId);
        response.setHeader("Retry-After", 10);
        response.send(202, "Tests are still running.");
    }
    else { // Results are ready
        response.setHeader("content-type", "application/json");
        if (resultsObject["verdict"] === "success" || resultsObject["verdict"] === "failure") { // If tests finished without errors, send response with status code 200.
            response.send(200, resultsObject);
        }
        else if (resultsObject["verdict"] === "error") { // If there was an error while running the tests, send response with status code 500
            response.send(500, resultsObject);
            ResultsManager.deleteSuiteResult(runId); // In case of an error while running test suite, delete suite results once user knows about it.
        }
    }
}