All files / src/hooks/common useCheckEnvironment.ts

77.27% Statements 17/22
35.71% Branches 5/14
100% Functions 2/2
77.27% Lines 17/22

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 44518x 518x   518x 24690x 24690x 24690x 24690x 24690x 24690x   24690x 66x 66x                 24690x 24690x         24690x 24690x   24690x                        
const ENVIRONMENT = process.env.VITE_ENVIRONMENT;
const NODE_ENV = process.env.NODE_ENV;
 
const useCheckEnvironment = () => {
  const baseEnv = ENVIRONMENT?.replace("local.", "");
  const isStaging = baseEnv === "staging";
  const isDevelopment = baseEnv === "development";
  const isProduction = baseEnv === "production";
  const isLocal = NODE_ENV === "development";
  const isTestEnv = NODE_ENV === "test";
 
  const getEnvironmentDomain = () => {
    if (isTestEnv) {
      return "";
    } else Eif (isProduction) {
      return "";
    } else if (isLocal) {
      return `local.${baseEnv}`;
    } else {
      return baseEnv;
    }
  };
  const subdomain = isLocal ? "local." : "portal.";
  const domain = isProduction
    ? ""
    : isDevelopment
    ? "development."
    : "staging.";
  const port = isLocal ? ":3000" : "";
  const platformBaseUrl = `https://${subdomain}${domain}givepayments.com${port}`;
 
  return {
    isStaging,
    isDevelopment,
    isProduction,
    isLocal,
    getEnvironmentDomain,
    platformBaseUrl,
    domain,
  };
};
 
export default useCheckEnvironment;