mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-02 22:26:57 -05:00
Start to fix tests + add more factories (#334)
* Stop using npm run migrate:reset in tests * Begin moving other existing fixtures to factories * Update cypress/support/index.ts Co-authored-by: Kalle <38327916+Sendouc@users.noreply.github.com> * Clean up usage of _.sample * Rename files * Remove incomplete building of associations * Add missing references to calendarEvent * Remove inaccurate seeds * Add explicit lodash devDependency Co-authored-by: Kalle <38327916+Sendouc@users.noreply.github.com>
This commit is contained in:
parent
9d80b3b3d9
commit
15ff99bc9e
|
|
@ -14,5 +14,5 @@ Cypress.Commands.add("login", (user: "sendou" | "nzap") => {
|
|||
|
||||
beforeEach(() => {
|
||||
// TODO: use database transactions, instead of dropping and recreating the database with each individual test
|
||||
cy.exec("npm run migrate:reset -- --force");
|
||||
cy.exec("npm run seed");
|
||||
});
|
||||
|
|
|
|||
13
package-lock.json
generated
13
package-lock.json
generated
|
|
@ -63,6 +63,7 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"cypress": "^6.8.0",
|
||||
"fishery": "^1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"prettier": "^2.2.1",
|
||||
"prisma": "^2.20.1",
|
||||
"ts-node": "^9.1.1",
|
||||
|
|
@ -5967,9 +5968,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.20",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
||||
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"node_modules/lodash.camelcase": {
|
||||
"version": "4.3.0",
|
||||
|
|
@ -14351,9 +14352,9 @@
|
|||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.20",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
||||
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"lodash.camelcase": {
|
||||
"version": "4.3.0",
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"cypress": "^6.8.0",
|
||||
"fishery": "^1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"prettier": "^2.2.1",
|
||||
"prisma": "^2.20.1",
|
||||
"ts-node": "^9.1.1",
|
||||
|
|
|
|||
21
prisma/factories/plusStatus.ts
Normal file
21
prisma/factories/plusStatus.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { Factory } from "fishery";
|
||||
import { PlusStatus, PlusRegion } from "@prisma/client";
|
||||
import prisma from "../client";
|
||||
import _ from "lodash";
|
||||
|
||||
export default Factory.define<PlusStatus>(({ params, onCreate }) => {
|
||||
onCreate(plusStatus => {
|
||||
return prisma.plusStatus.create({ data: plusStatus });
|
||||
});
|
||||
|
||||
return {
|
||||
userId: 1, // TODO: automatically build a User object, if necessary
|
||||
membershipTier: 1,
|
||||
region: _.sample(Object.values(PlusRegion))!,
|
||||
voucherId: null,
|
||||
vouchTier: null,
|
||||
canVouchFor: null,
|
||||
canVouchAgainAfter: null,
|
||||
nameForVoting: null
|
||||
};
|
||||
});
|
||||
18
prisma/factories/plusSuggestion.ts
Normal file
18
prisma/factories/plusSuggestion.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Factory } from "fishery";
|
||||
import { PlusSuggestion } from "@prisma/client";
|
||||
import prisma from "../client";
|
||||
|
||||
export default Factory.define<PlusSuggestion>(({ params, onCreate }) => {
|
||||
onCreate(plusSuggestion => {
|
||||
return prisma.plusSuggestion.create({ data: plusSuggestion });
|
||||
});
|
||||
|
||||
return {
|
||||
suggestedId: 1, // TODO: automatically build a User object, if necessary
|
||||
suggesterId: 2, // TODO: automatically build a User object, if necessary
|
||||
tier: 1,
|
||||
description: "yooo so cracked",
|
||||
isResuggestion: false,
|
||||
createdAt: new Date()
|
||||
};
|
||||
});
|
||||
20
prisma/factories/plusVotingSummary.ts
Normal file
20
prisma/factories/plusVotingSummary.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { Factory } from "fishery";
|
||||
import { PlusVotingSummary } from "@prisma/client";
|
||||
import prisma from "../client";
|
||||
|
||||
export default Factory.define<PlusVotingSummary>(({ params, onCreate }) => {
|
||||
onCreate(plusVotingSummary => {
|
||||
return prisma.plusVotingSummary.create({ data: plusVotingSummary });
|
||||
});
|
||||
|
||||
return {
|
||||
userId: 1, // TODO: automatically build a User object, if necessary
|
||||
month: 1,
|
||||
tier: 1,
|
||||
year: 2020,
|
||||
wasVouched: false,
|
||||
wasSuggested: false,
|
||||
countsEU: [0, 0, 0, 3],
|
||||
countsNA: [0, 0, 2, 0]
|
||||
};
|
||||
});
|
||||
|
|
@ -1,82 +1,75 @@
|
|||
import { Prisma } from "@prisma/client";
|
||||
import { PlusRegion, Prisma } from "@prisma/client";
|
||||
import plusStatusFactory from "../factories/plusStatus";
|
||||
import plusSuggestionFactory from "../factories/plusSuggestion";
|
||||
import plusVotingSummaryFactory from "../factories/plusVotingSummary";
|
||||
|
||||
// TODO: All this data is currently hard-coded so that Cypress tests will pass.
|
||||
// In the future, we could allow the data generated by these factories be more random, and
|
||||
// update the tests so that they are responsible for creating the specific data that they want to check.
|
||||
|
||||
export const getPlusStatusesData = (): Prisma.PlusStatusCreateManyInput[] => {
|
||||
return [
|
||||
{
|
||||
userId: 1,
|
||||
region: "EU",
|
||||
membershipTier: 1,
|
||||
canVouchAgainAfter: new Date(Date.UTC(2020, 1, 1)),
|
||||
},
|
||||
{
|
||||
userId: 2,
|
||||
region: "NA",
|
||||
membershipTier: 1,
|
||||
},
|
||||
{
|
||||
userId: 3,
|
||||
region: "EU",
|
||||
membershipTier: 1,
|
||||
},
|
||||
{
|
||||
userId: 4,
|
||||
region: "NA",
|
||||
membershipTier: 1,
|
||||
},
|
||||
{
|
||||
userId: 5,
|
||||
region: "EU",
|
||||
membershipTier: 1,
|
||||
},
|
||||
{
|
||||
userId: 6,
|
||||
region: "NA",
|
||||
membershipTier: 2,
|
||||
vouchTier: 1,
|
||||
},
|
||||
{
|
||||
userId: 7,
|
||||
region: "EU",
|
||||
membershipTier: 2,
|
||||
},
|
||||
{
|
||||
userId: 8,
|
||||
region: "NA",
|
||||
membershipTier: 2,
|
||||
},
|
||||
{
|
||||
userId: 9,
|
||||
region: "EU",
|
||||
membershipTier: 2,
|
||||
},
|
||||
{
|
||||
userId: 10,
|
||||
region: "NA",
|
||||
},
|
||||
{
|
||||
userId: 333,
|
||||
region: "EU",
|
||||
region: PlusRegion.EU,
|
||||
membershipTier: 2,
|
||||
canVouchAgainAfter: new Date(Date.UTC(2030, 1, 1)),
|
||||
canVouchFor: 2,
|
||||
},
|
||||
{
|
||||
userId: 999,
|
||||
region: "EU",
|
||||
membershipTier: 1,
|
||||
region: PlusRegion.EU,
|
||||
canVouchFor: 1,
|
||||
},
|
||||
];
|
||||
}
|
||||
].map((params) => {
|
||||
return plusStatusFactory.build(params);
|
||||
});
|
||||
};
|
||||
|
||||
export const getPlusSuggestionsData = (): Prisma.PlusSuggestionCreateManyInput[] => {
|
||||
return [
|
||||
{
|
||||
plusSuggestionFactory.build({
|
||||
description: "yooo so cracked",
|
||||
tier: 2,
|
||||
suggestedId: 10,
|
||||
suggesterId: 1,
|
||||
},
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
|
|
@ -84,125 +77,73 @@ export const getPlusVotingSummaryData = (): Prisma.PlusVotingSummaryCreateManyIn
|
|||
return [
|
||||
{
|
||||
userId: 1,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 0, 0, 3],
|
||||
countsNA: [0, 0, 2, 0],
|
||||
},
|
||||
{
|
||||
userId: 2,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 3, 0, 0],
|
||||
countsNA: [2, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
userId: 3,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [1, 1, 1, 0],
|
||||
countsNA: [0, 1, 1, 0],
|
||||
},
|
||||
{
|
||||
userId: 4,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 1, 2, 0],
|
||||
countsNA: [2, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
userId: 5,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [1, 0, 1, 1],
|
||||
countsNA: [0, 2, 0, 0],
|
||||
},
|
||||
{
|
||||
userId: 6,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: true,
|
||||
year: 2020,
|
||||
countsEU: [0, 3, 0, 0],
|
||||
countsNA: [2, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
userId: 7,
|
||||
month: 1,
|
||||
tier: 1,
|
||||
wasSuggested: false,
|
||||
wasVouched: true,
|
||||
year: 2020,
|
||||
countsEU: [0, 0, 0, 3],
|
||||
countsNA: [0, 0, 2, 0],
|
||||
},
|
||||
// +2
|
||||
{
|
||||
userId: 6,
|
||||
month: 1,
|
||||
tier: 2,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 0, 2, 0],
|
||||
countsNA: [0, 0, 0, 2],
|
||||
},
|
||||
|
||||
{
|
||||
userId: 7,
|
||||
month: 1,
|
||||
tier: 2,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 1, 0, 1],
|
||||
countsNA: [0, 1, 1, 0],
|
||||
},
|
||||
{
|
||||
userId: 8,
|
||||
month: 1,
|
||||
tier: 2,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 2, 0, 0],
|
||||
countsNA: [0, 0, 2, 0],
|
||||
},
|
||||
{
|
||||
userId: 9,
|
||||
month: 1,
|
||||
tier: 2,
|
||||
wasSuggested: false,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [1, 1, 0, 0],
|
||||
countsNA: [0, 2, 0, 0],
|
||||
},
|
||||
{
|
||||
userId: 10,
|
||||
month: 1,
|
||||
tier: 2,
|
||||
wasSuggested: true,
|
||||
wasVouched: false,
|
||||
year: 2020,
|
||||
countsEU: [0, 0, 2, 0],
|
||||
countsNA: [0, 0, 0, 2],
|
||||
},
|
||||
];
|
||||
].map((params) => {
|
||||
return plusVotingSummaryFactory.build(params);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import prisma from "./client";
|
||||
import calendarEventFactory from "./factories/calendarEvent";
|
||||
import userFactory from "./factories/user";
|
||||
import {
|
||||
getPlusStatusesData,
|
||||
getPlusSuggestionsData,
|
||||
getPlusVotingSummaryData,
|
||||
getPlusSuggestionsData,
|
||||
getPlusStatusesData,
|
||||
} from "./mocks/plus";
|
||||
import userFactory from "./factories/user"
|
||||
import calendarEventFactory from "./factories/calendarEvent"
|
||||
|
||||
async function main() {
|
||||
throwIfNotLocalhost();
|
||||
await dropAllData();
|
||||
await seedNewData();
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +38,23 @@ function throwIfNotLocalhost() {
|
|||
);
|
||||
}
|
||||
|
||||
async function dropAllData() {
|
||||
// TODO: Programatically clear/truncate all tables, rather than listing each model individually
|
||||
// That way, we won't need to update this method each time we add a new model
|
||||
await prisma.profile.deleteMany({});
|
||||
await prisma.build.deleteMany({});
|
||||
await prisma.salmonRunRecord.deleteMany({});
|
||||
await prisma.freeAgentPost.deleteMany({});
|
||||
await prisma.team.deleteMany({});
|
||||
await prisma.ladderPlayerTrueSkill.deleteMany({});
|
||||
await prisma.ladderMatchPlayer.deleteMany({});
|
||||
await prisma.plusVotingSummary.deleteMany({});
|
||||
await prisma.plusSuggestion.deleteMany({});
|
||||
await prisma.plusStatus.deleteMany({});
|
||||
await prisma.calendarEvent.deleteMany({});
|
||||
await prisma.user.deleteMany({});
|
||||
}
|
||||
|
||||
async function seedNewData() {
|
||||
await seedUsers();
|
||||
await seedEvents();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user