'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});


/**
 * Convert specsResults from object to array and add the spec file
 * @param {Object} versionModel 
 */
function specsResultstoArray(versionModel) {
  if (versionModel.specsResults && !Array.isArray(versionModel.specsResults)) {
    // Get the first found spec file
    // This should be ok since when the specs results was an object there were only one spec file
    var specFile = versionModel.files.filter(function (file) {
      return file.test;
    })[0];
    var oldSpecsResults = versionModel.specsResults;
    // Add the spec file path
    oldSpecsResults.specFile = specFile.relativePath;
    var specsResults = [oldSpecsResults];
    versionModel.specsResults = specsResults;
  }
  return versionModel;
}

exports.default = {
  name: 'convert specs results array',
  migrate: specsResultstoArray
};