Fix regression with "unit" testing (haha)

This commit is contained in:
zkldi
2022-01-10 09:56:58 +00:00
parent 1ddb3318fa
commit 46700da572
2 changed files with 15 additions and 0 deletions
@@ -6,6 +6,7 @@ import db from "external/mongo/db";
import UpdateScore from "./update-score";
import { CreateScoreID } from "lib/score-import/framework/score-importing/score-id";
import ResetDBState from "test-utils/resets";
import { rootLogger } from "lib/logger/logger";
const mockImportDocument: ImportDocument = {
userID: 1,
@@ -61,8 +62,12 @@ t.test("#UpdateScore", (t) => {
scoreData: { score: 1020 },
} as any);
delete score._id;
const newScoreID = CreateScoreID(score.userID, score, score.chartID);
rootLogger.crit(newScoreID);
await db.imports.insert(mockImportDocument);
await db.sessions.insert(mockSessionDocument);
@@ -4,6 +4,7 @@ import { KtLogger, rootLogger } from "lib/logger/logger";
import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data";
import { UpdateChartRanking } from "lib/score-import/framework/pb/create-pb-doc";
import { CreateScoreID } from "lib/score-import/framework/score-importing/score-id";
import { id } from "monk";
import { ScoreDocument } from "tachi-common";
import { UpdateAllPBs } from "utils/calculations/recalc-scores";
import { FormatUserDoc, GetUserWithID } from "utils/user";
@@ -67,6 +68,15 @@ export default async function UpdateScore(oldScore: ScoreDocument, newScore: Sco
);
try {
// Having _id defined will cause this to throw, causing it to not apply
// the update.
if (newScore._id) {
logger.warn(
`Passed a score with _id to UpdateScore. This property should not be set. Deleting this property and continuing anyway.`
);
// This property shouldn't be defined.
delete newScore._id;
}
await db.scores.update(
{
scoreID: oldScoreID,