All files / Rindu/utils getValidCookieLocale.ts

40% Statements 4/10
0% Branches 0/5
0% Functions 0/1
44.44% Lines 4/9

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 1445x 45x 45x     4x                
import { LOCALE_COOKIE } from "./constants";
import { takeCookie } from "./cookies";
import { isLocale, Locale } from "./locale";
import { ServerApiContext } from "types/serverContext";
 
export function getValidCookieLocale(context: ServerApiContext): Locale | null {
  const localeHeader = context.req.headers["x-locale"]?.toString();
  const localeCookieValue = takeCookie(LOCALE_COOKIE, context);
  const localeCookie = localeCookieValue ?? localeHeader;
  Iif (localeCookie && isLocale(localeCookie)) return localeCookie;
 
  return null;
}