"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _jsonHelper = require("../utils/jsonHelper");

var _default = (resultObj, coverage, status = true, type = 'unitcase', filecoverage = 0) => {
  let pathArray = [];
  let resultJson = {};
  resultJson.isExecuted = status;
  resultJson.numberOfSuccess = resultObj.numPassedTests;
  resultJson.numberOfFails = resultObj.numFailedTests;
  resultJson.numberOfCases = resultObj.numTotalTests;
  resultJson.numberOfSuites = resultObj.numTotalTestSuites;
  resultJson.endTime = resultObj.endTime;
  resultJson.startTime = resultObj.startTime;
  resultJson.coverageDetail = {
    codeCoveragePercentage: coverage,
    fileCoveragePercentage: filecoverage
  };
  let fileDetailList = [];
  resultObj.testResults.map(testFile => {
    let fileObj = {};
    fileObj.fileName = testFile.testFilePath;
    fileObj.CaseList = {};
    fileObj.CaseList.passedCaseList = [];
    fileObj.CaseList.failedCaseList = [];
    testFile.testResults.map(testCase => {
      if (testCase.status === 'failed') {
        fileObj.CaseList.failedCaseList.push(testCase.title);
      } else if (testCase.status === 'passed') {
        fileObj.CaseList.passedCaseList.push(testCase.title);
      }

      return testCase;
    });
    fileDetailList.push(fileObj);
    return testFile;
  });

  if (type !== 'unitcase') {
    Array.prototype.push.apply(pathArray, ['tests', 'modifiedFileUnitCase']);
  } else {
    Array.prototype.push.apply(pathArray, ['tests', 'unitCase']);
  }

  resultJson.fileDetails = fileDetailList;
  (0, _jsonHelper.jsonHelper)(`${process.cwd()}/result.json`, pathArray, resultJson);
};

exports.default = _default;