mavend/octoboard

View on GitHub
src/utils/generators/names.js

Summary

Maintainability
A
0 mins
Test Coverage
F
33%
import en from "./locales/en.json";
import pl from "./locales/pl.json";
import { sample } from "lodash";

const languages = { en, pl };

export function generateName(lang) {
  // This should be possible with jest mocks, but I can't figure out how to do it 🤷‍♀️
  if (process.env.NODE_ENV === "test") return `${lang} test`;
  const langDict = languages[lang] || languages.en;
  const adjective = sample(langDict.adjective);
  const noun = sample(langDict.noun);
  return [adjective, noun].join(" ");
}