All files / publisher/listing/utils shouldShowUpdateMetadataWarning.ts

100% Statements 16/16
100% Branches 22/22
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67          2x   2x 4x 2x     4x           1x     4x         1x     4x 1x       2x                                       2x   2x 5x 1x       2x        
interface DirtyField {
  [key: string]: any;
}
 
function shouldShowUpdateMetadataWarning(dirtyFields: DirtyField) {
  const filteredDirtyFields = [];
 
  for (const [key, value] of Object.entries(dirtyFields)) {
    if (value === true && key !== "banner_urls" && key !== "icon_url") {
      filteredDirtyFields.push(key);
    }
 
    if (
      key === "banner_urls" &&
      value === true &&
      !filteredDirtyFields.includes("banner") &&
      !filteredDirtyFields.includes("screenshot_urls")
    ) {
      filteredDirtyFields.push("banner");
    }
 
    if (
      key === "icon_url" &&
      value === true &&
      !filteredDirtyFields.includes("icon")
    ) {
      filteredDirtyFields.push("icon");
    }
 
    if (key === "screenshot_urls" && value === true) {
      filteredDirtyFields.push("screenshot_urls");
    }
  }
 
  const allowedKeys = [
    "banner",
    "icon",
    "primary-category",
    "screenshot_urls",
    "secondary-category",
    "video_urls",
    // ========================================================
    // The following keys can be uncommented once
    // https://bugs.launchpad.net/snapstore-server/+bug/2011695
    // is resolved.
    // We are tracking this internally here:
    // https://warthogs.atlassian.net/browse/WD-2648
    // ========================================================
    // "public_metrics_blacklist",
    // "public_metrics_distros",
    // "public_metrics_enabled",
    // "public_metrics_territories",
  ];
 
  let showWarning = false;
 
  filteredDirtyFields.forEach((field) => {
    if (!allowedKeys.includes(field)) {
      showWarning = true;
    }
  });
 
  return showWarning;
}
 
export default shouldShowUpdateMetadataWarning;