mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Seed via HTTP call
This commit is contained in:
parent
163d72d2e4
commit
60e9e16bcd
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<string, LoggedInUser> = {
|
||||
sendou: {
|
||||
id: ADMIN_UUID,
|
||||
discordId: "79237403620945920",
|
||||
discordAvatar: "fcfd65a3bea598905abb9ca25296816b",
|
||||
id: ADMIN_TEST_UUID,
|
||||
discordId: ADMIN_TEST_DISCORD_ID,
|
||||
discordAvatar: ADMIN_TEST_AVATAR,
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
"resolveJsonModule": true,
|
||||
"target": "ES2019",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"types": ["cypress"],
|
||||
"paths": {
|
||||
"~/*": ["./app/*"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user