Skip to content

Commit

Permalink
Merge pull request #22 from brandon-schabel/ci-testing
Browse files Browse the repository at this point in the history
Split Server Code Into Smaller functions and Modules
  • Loading branch information
brandon-schabel authored Sep 14, 2023
2 parents a379920 + 6184526 commit 18aff33
Show file tree
Hide file tree
Showing 27 changed files with 1,520 additions and 251 deletions.
112 changes: 112 additions & 0 deletions modules/data-gen-factory/cities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { randFromArray } from "./rand-num";

const cities = [
"Albany",
"Austin",
"Baltimore",
"Boston",
"Charlotte",
"Chicago",
"Dallas",
"Denver",
"Detroit",
"Houston",
"Indianapolis",
"Jacksonville",
"Kansas City",
"Las Vegas",
"Los Angeles",
"Louisville",
"Memphis",
"Miami",
"Minneapolis",
"Nashville",
"New Orleans",
"New York",
"Oklahoma City",
"Orlando",
"Philadelphia",
"Phoenix",
"Portland",
"Raleigh",
"Sacramento",
"San Antonio",
"San Diego",
"San Francisco",
"San Jose",
"Seattle",
"St. Louis",
"Tampa",
"Washington, D.C.",
"Albuquerque",
"Atlanta",
"Boise",
"Buffalo",
"Cincinnati",
"Cleveland",
"Columbus",
"Des Moines",
"El Paso",
"Fort Worth",
"Fresno",
"Honolulu",
"Indianapolis",
"Jacksonville",
"Kansas City",
"Las Vegas",
"Little Rock",
"Madison",
"Manchester",
"Milwaukee",
"Mobile",
"Montgomery",
"Newark",
"Oakland",
"Omaha",
"Pittsburgh",
"Reno",
"Richmond",
"Riverside",
"Salt Lake City",
"Santa Ana",
"Savannah",
"Syracuse",
"Tacoma",
"Toledo",
"Tucson",
"Tulsa",
"Virginia Beach",
"Wichita",
"Wilmington",
"Anchorage",
"Arlington",
"Aurora",
"Bakersfield",
"Chandler",
"Chesapeake",
"Chula Vista",
"Durham",
"Fremont",
"Garland",
"Gilbert",
"Glendale",
"Hialeah",
"Irvine",
"Irving",
"Laredo",
"Mesa",
"Norfolk",
"North Las Vegas",
"Plano",
"Raleigh",
"Riverside",
"Rochester",
"Scottsdale",
"Spokane",
"Stockton",
"Toledo",
];

export const getRandomCity = () => {
return randFromArray(cities);
};
204 changes: 204 additions & 0 deletions modules/data-gen-factory/countries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import { randFromArray } from "./rand-num";

const countries = [
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
"Belgium",
"Belize",
"Benin",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Brazil",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cabo Verde",
"Cambodia",
"Cameroon",
"Canada",
"Central African Republic",
"Chad",
"Chile",
"China",
"Colombia",
"Comoros",
"Congo",
"Costa Rica",
"Croatia",
"Cuba",
"Cyprus",
"Czech Republic",
"Democratic Republic of the Congo",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"East Timor",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Estonia",
"Eswatini",
"Ethiopia",
"Fiji",
"Finland",
"France",
"Gabon",
"Gambia",
"Georgia",
"Germany",
"Ghana",
"Greece",
"Grenada",
"Guatemala",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Haiti",
"Honduras",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Israel",
"Italy",
"Ivory Coast",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Kosovo",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",
"Mauritius",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Montenegro",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"North Macedonia",
"Norway",
"Oman",
"Pakistan",
"Palau",
"Palestine",
"Panama",
"Papua New Guinea",
"Paraguay",
"Peru",
"Philippines",
"Poland",
"Portugal",
"Qatar",
"Romania",
"Russia",
"Rwanda",
"Saint Kitts and Nevis",
"Saint Lucia",
"Saint Vincent and the Grenadines",
"Samoa",
"San Marino",
"Sao Tome and Principe",
"Saudi Arabia",
"Senegal",
"Serbia",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"South Korea",
"South Sudan",
"Spain",
"Sri Lanka",
"Sudan",
"Suriname",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tonga",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Tuvalu",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States of America",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Vatican City",
"Venezuela",
"Vietnam",
"Yemen",
"Zambia",
"Zimbabwe",
];

export const getRandomCountry = () => {
return randFromArray(countries);
};
36 changes: 36 additions & 0 deletions modules/data-gen-factory/create-random-data.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, it } from "bun:test";
import { dataGenerators } from "./object-gen";
import { createRandomData } from "./create-random-data";

describe("createRandomData", () => {
it("should return an object with the correct keys", () => {
const config = {
firstName: { type: "firstName" },
lastName: { type: "lastName" },
age: { type: "num", min: 18, max: 65 },
} as const;
const result = createRandomData(config);
expect(result).toHaveProperty("firstName");
expect(result).toHaveProperty("lastName");
expect(result).toHaveProperty("age");
});

it("should return a number within the specified range for num type config", () => {
const config = {
age: { type: "num", min: 18, max: 65 },
} as const;
const result = createRandomData(config);
expect(result.age).toBeGreaterThanOrEqual(18);
expect(result.age).toBeLessThanOrEqual(65);
});

it("should return a string for non-num type config", () => {
const config = {
firstName: { type: "firstName" },
lastName: { type: "lastName" },
} as const;
const result = createRandomData(config);
expect(typeof result.firstName).toBe("string");
expect(typeof result.lastName).toBe("string");
});
});
Loading

0 comments on commit 18aff33

Please sign in to comment.