All files / publisher/utils getSettingsData.ts

100% Statements 17/17
100% Branches 10/10
100% Functions 4/4
100% Lines 17/17

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      10x 3x     7x       10x       5x   5x         10x 1x     9x 1x     8x       10x 10x   10x     10x     10x   10x        
import { FieldValues } from "react-hook-form";
 
function getCountryKeysStatus(settingsData: FieldValues) {
  if (settingsData?.blacklist_country_keys) {
    return "exclude";
  }
 
  return "include";
}
 
function getTerritoryDistributionStatus(data: FieldValues) {
  if (
    data?.whitelist_countries.length > 0 ||
    data?.blacklist_countries.length > 0
  ) {
    return "custom";
  } else {
    return "all";
  }
}
 
function getVisibilityStatus(data: FieldValues) {
  if (data?.unlisted) {
    return "unlisted";
  }
 
  if (data?.private) {
    return "private";
  }
 
  return "public";
}
 
function getSettingsData(settingsData: FieldValues) {
  settingsData.visibility = getVisibilityStatus(settingsData);
  settingsData.territory_distribution_status =
    getTerritoryDistributionStatus(settingsData);
  settingsData.whitelist_country_keys = settingsData?.whitelist_countries
    .sort()
    .join(" ");
  settingsData.blacklist_country_keys = settingsData?.blacklist_countries
    .sort()
    .join(" ");
  settingsData.country_keys_status = getCountryKeysStatus(settingsData);
 
  return settingsData;
}
 
export default getSettingsData;