diff --git a/app/constants.ts b/app/constants.ts index 9011c1f1e..114988659 100644 --- a/app/constants.ts +++ b/app/constants.ts @@ -44,3 +44,7 @@ export const navItems = [ items: ["badges", "links"], }, ]; + +export const ADMIN_TEST_UUID = "846e12eb-d373-4002-a0c3-e23077e1c88c"; +export const ADMIN_TEST_DISCORD_ID = "79237403620945920"; +export const ADMIN_TEST_AVATAR = "fcfd65a3bea598905abb9ca25296816b"; diff --git a/cypress/integration/tournament.spec.ts b/cypress/integration/tournament.spec.ts index 4eddb6211..2c6000859 100644 --- a/cypress/integration/tournament.spec.ts +++ b/cypress/integration/tournament.spec.ts @@ -1,5 +1,5 @@ describe("Before tournament starts", () => { - before(() => { + beforeEach(() => { cy.seed(); cy.intercept( "GET", @@ -12,12 +12,12 @@ describe("Before tournament starts", () => { cy.visit("/to/sendou/in-the-zone-x"); cy.title().should("include", "In The Zone X"); cy.getCy("register-button").click(); - cy.getCy("team-name-input").type("Anaheim"); + cy.getCy("team-name-input").type("Team Olive"); cy.getCy("register-submit-button").click(); cy.contains("Team name already taken"); cy.wait("@tournaments"); - cy.getCy("team-name-input").clear().type("Team Olive"); + cy.getCy("team-name-input").clear().type("Team Olive V2"); cy.getCy("register-submit-button").click(); cy.url().should("include", "manage-roster"); }); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 0e41f7c94..240c6c258 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -1,5 +1,9 @@ -import { ADMIN_UUID } from "../../prisma/seed"; -import { LoggedInUser } from "~/utils"; +import { + ADMIN_TEST_AVATAR, + ADMIN_TEST_DISCORD_ID, + ADMIN_TEST_UUID, +} from "../../app/constants"; +import type { LoggedInUser } from "~/utils"; export {}; @@ -21,15 +25,15 @@ Cypress.Commands.add("getCy", (value: string) => { }); Cypress.Commands.add("seed", () => { - cy.exec("npm run seed:reset"); + cy.request("POST", "seed"); }); Cypress.Commands.add("logIn", (user: MockUser) => { const mockUsers: Record = { sendou: { - id: ADMIN_UUID, - discordId: "79237403620945920", - discordAvatar: "fcfd65a3bea598905abb9ca25296816b", + id: ADMIN_TEST_UUID, + discordId: ADMIN_TEST_DISCORD_ID, + discordAvatar: ADMIN_TEST_AVATAR, }, } as const; diff --git a/prisma/seed.ts b/prisma/seed.ts index 23d7cac11..0c6ba0bfc 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,59 +1,64 @@ import { PrismaClient } from "@prisma/client"; -import { stages as stagesList } from "../app/constants"; +import { + ADMIN_TEST_AVATAR, + ADMIN_TEST_DISCORD_ID, + ADMIN_TEST_UUID, + stages as stagesList, +} from "../app/constants"; import { readFile } from "fs/promises"; import path from "path"; import crypto from "crypto"; const prisma = new PrismaClient(); -export const ADMIN_UUID = "846e12eb-d373-4002-a0c3-e23077e1c88c"; -export const ADMIN_DISCORD_ID = "79237403620945920"; -export const ADMIN_AVATAR = "fcfd65a3bea598905abb9ca25296816b"; +export async function seed() { + try { + // + // make sure we won't override production database + // + if (!process.env.DATABASE_URL?.includes("localhost")) { + throw Error( + "Trying to seed a database not in localhost or DATABASE_URL env var is not set" + ); + } -async function main() { - // - // make sure we won't override production database - // - if (!process.env.DATABASE_URL?.includes("localhost")) { - throw Error( - "Trying to seed a database not in localhost or DATABASE_URL env var is not set" - ); + // + // wipe database + // + await prisma.tournamentTeamMember.deleteMany(); + await prisma.tournamentTeam.deleteMany(); + await prisma.tournament.deleteMany(); + await prisma.organization.deleteMany(); + await prisma.user.deleteMany(); + await prisma.stage.deleteMany(); + + // + // create mock data + // + const adminUserCreated = await adminUser(); + const userIds = new Array(500).fill(null).map(() => crypto.randomUUID()); + await users(userIds); + const organization = await organizations(adminUserCreated.id); + const tournament = await tournaments(organization.id); + await tournamentTeams(tournament.id, userIds); + const stageIds = await stages(); + await tournamentAddMaps(tournament.id, stageIds); + } finally { + await prisma.$disconnect(); } - - // - // wipe database - // - await prisma.tournamentTeamMember.deleteMany(); - await prisma.tournamentTeam.deleteMany(); - await prisma.tournament.deleteMany(); - await prisma.organization.deleteMany(); - await prisma.user.deleteMany(); - await prisma.stage.deleteMany(); - - // - // create mock data - // - const adminUserCreated = await adminUser(); - const userIds = new Array(500).fill(null).map(() => crypto.randomUUID()); - await users(userIds); - const organization = await organizations(adminUserCreated.id); - const tournament = await tournaments(organization.id); - await tournamentTeams(tournament.id, userIds); - const stageIds = await stages(); - await tournamentAddMaps(tournament.id, stageIds); } async function adminUser() { return prisma.user.create({ data: { - id: ADMIN_UUID, + id: ADMIN_TEST_UUID, discordDiscriminator: "4059", - discordId: ADMIN_DISCORD_ID, + discordId: ADMIN_TEST_DISCORD_ID, discordName: "Sendou", discordRefreshToken: "none", twitch: "Sendou", youtubeId: "UCWbJLXByvsfQvTcR4HLPs5Q", youtubeName: "Sendou", - discordAvatar: ADMIN_AVATAR, + discordAvatar: ADMIN_TEST_AVATAR, twitter: "sendouc", }, }); @@ -195,12 +200,3 @@ async function stages() { return result; } - -main() - .catch((e) => { - console.error(e); - process.exit(1); - }) - .finally(async () => { - await prisma.$disconnect(); - }); diff --git a/server/index.ts b/server/index.ts index 8312ff3d1..fba27634f 100644 --- a/server/index.ts +++ b/server/index.ts @@ -4,6 +4,7 @@ import compression from "compression"; import morgan from "morgan"; import { createRequestHandler } from "@remix-run/express"; import { setUpAuth } from "./auth"; +import { seed } from "../prisma/seed"; const MODE = process.env.NODE_ENV; const BUILD_DIR = path.join(process.cwd(), "server/build"); @@ -36,6 +37,14 @@ function userToContext(req: Express.Request) { return { user: req.user }; } +if (process.env.NODE_ENV === "development") { + app.post("/seed", async (_req, res) => { + await seed(); + + res.status(200).end(); + }); +} + app.all( "*", MODE === "production" diff --git a/tsconfig.json b/tsconfig.json index 08d2bcda5..8c2e040d1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,8 @@ "resolveJsonModule": true, "target": "ES2019", "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "types": ["cypress"], "paths": { "~/*": ["./app/*"]