actually, rename it, but commit all the way.

This commit is contained in:
zkldi
2021-07-24 03:21:10 +01:00
parent a0c3f56c12
commit 05dae6d2ab
8 changed files with 30 additions and 30 deletions
@@ -20,7 +20,7 @@ import pbsRouter from "./pbs/router";
import sessionsRouter from "./sessions/router";
import foldersFolderIDRouter from "./folders/_folderID/router";
import tablesRouter from "./tables/router";
import statsRouter from "./stats/router";
import showcaseRouter from "./showcase/router";
import settingsRouter from "./settings/router";
const router: Router = Router({ mergeParams: true });
@@ -404,7 +404,7 @@ router.get("/leaderboard-adjacent", async (req, res) => {
router.use("/pbs", pbsRouter);
router.use("/sessions", sessionsRouter);
router.use("/tables", tablesRouter);
router.use("/stats", statsRouter);
router.use("/showcase", showcaseRouter);
router.use("/settings", settingsRouter);
router.use("/folders/:folderID", foldersFolderIDRouter);
@@ -42,9 +42,9 @@ t.beforeEach(async () => {
await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}));
});
t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
t.test("Should return the evaluated stats for this user.", async (t) => {
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/stats");
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/showcase");
t.hasStrict(res.body.body, [
{
@@ -95,7 +95,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
id: 2,
} as PrivateUserDocument);
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/stats?projectUser=2");
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/showcase?projectUser=2");
t.hasStrict(res.body.body, [
{
@@ -113,7 +113,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
});
t.test("Should return 404 if the user has not played this game.", async (t) => {
const res = await mockApi.get("/api/v1/users/1/games/bms/7K/stats");
const res = await mockApi.get("/api/v1/users/1/games/bms/7K/showcase");
t.equal(res.statusCode, 404);
@@ -125,10 +125,10 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
t.end();
});
t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom", (t) => {
t.test("Should return a custom folder evaluated stat on a user.", async (t) => {
const res = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade&gte=3&folderID=${TestingIIDXFolderSP10.folderID}`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade&gte=3&folderID=${TestingIIDXFolderSP10.folderID}`
);
t.strictSame(res.body.body, {
@@ -141,7 +141,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
t.test("Should return a custom chart evaluated stat on a user.", async (t) => {
const res = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade&chartID=${Testing511SPA.chartID}`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade&chartID=${Testing511SPA.chartID}`
);
t.strictSame(res.body.body, {
@@ -153,13 +153,13 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
t.test("Should reject for invalid folderID.", async (t) => {
const res = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade&gte=4`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade&gte=4`
);
t.equal(res.statusCode, 400, "Should reject for no folderID");
const res2 = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade&gte=4&folderID=foo&folderID=bar`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade&gte=4&folderID=foo&folderID=bar`
);
t.equal(res2.statusCode, 400, "Should reject for non-string folderID");
@@ -169,13 +169,13 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
t.test("Should reject for invalid chartID.", async (t) => {
const res = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade&gte=4`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade&gte=4`
);
t.equal(res.statusCode, 400, "Should reject for no chartID");
const res2 = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade&chartID=foo&chartID=bar`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade&chartID=foo&chartID=bar`
);
t.equal(res2.statusCode, 400, "Should reject for non-string chartID");
@@ -185,7 +185,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
t.test("Should reject for invalid mode", async (t) => {
const res = await mockApi.get(
`/api/v1/users/1/games/iidx/SP/stats/custom?mode=nonsense&prop=grade&gte=4&chartID=foo`
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=nonsense&prop=grade&gte=4&chartID=foo`
);
t.equal(res.statusCode, 400);
@@ -197,7 +197,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => {
});
// @todo #239 PUT UGPT-Stats needs some tests for input validation.
t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
t.test("PUT /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
t.test("Requires the user to be authed as the requested user.", async (t) => {
await db["api-tokens"].insert({
userID: 2,
@@ -209,7 +209,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
});
const res = await mockApi
.put("/api/v1/users/1/games/iidx/SP/stats")
.put("/api/v1/users/1/games/iidx/SP/showcase")
.set("Authorization", `Bearer alt_token`);
t.equal(res.statusCode, 403);
@@ -228,7 +228,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
});
const res = await mockApi
.put("/api/v1/users/1/games/iidx/SP/stats")
.put("/api/v1/users/1/games/iidx/SP/showcase")
.set("Authorization", `Bearer alt_token`);
t.equal(res.statusCode, 403);
@@ -247,7 +247,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => {
});
const res = await mockApi
.put("/api/v1/users/1/games/iidx/SP/stats")
.put("/api/v1/users/1/games/iidx/SP/showcase")
.set("Authorization", `Bearer alt_token`)
.send([
{
@@ -1,15 +1,15 @@
import { Router } from "express";
import { SYMBOL_TachiData } from "../../../../../../../../../../lib/constants/tachi";
import { EvaluateUsersStatsShowcase } from "../../../../../../../../../../lib/showcase-stats/get-stats";
import { ResolveUser } from "../../../../../../../../../../utils/user";
import { SYMBOL_TachiData } from "lib/constants/tachi";
import { EvaluateUsersStatsShowcase } from "lib/showcase/get-stats";
import { ResolveUser } from "utils/user";
import p from "prudence";
import { FormatPrError } from "../../../../../../../../../../utils/prudence";
import { FormatPrError } from "utils/prudence";
import { ShowcaseStatDetails, GetGamePTConfig } from "tachi-common";
import { EvaluateShowcaseStat } from "../../../../../../../../../../lib/showcase-stats/evaluator";
import db from "../../../../../../../../../../external/mongo/db";
import { RequirePermissions } from "../../../../../../../../../middleware/auth";
import { RequireAuthedAsUser } from "../../../../middleware";
import { GetRelatedStatDocuments } from "lib/showcase-stats/get-related";
import { EvaluateShowcaseStat } from "lib/showcase/evaluator";
import db from "external/mongo/db";
import { RequirePermissions } from "server/middleware/auth";
import { RequireAuthedAsUser } from "server/router/api/v1/users/_userID/middleware";
import { GetRelatedStatDocuments } from "lib/showcase/get-related";
const router: Router = Router({ mergeParams: true });
/**
@@ -17,7 +17,7 @@ const router: Router = Router({ mergeParams: true });
*
* @param projectUser - Project another user's stats instead of their set stats.
*
* @name GET /api/v1/users/:userID/games/:game/:playtype/stats
* @name GET /api/v1/users/:userID/games/:game/:playtype/showcase
*/
router.get("/", async (req, res) => {
const user = req[SYMBOL_TachiData]!.requestedUser!;
@@ -59,7 +59,7 @@ router.get("/", async (req, res) => {
* @TODO: #237 This custom stat code accepts charts and folders from any game and any playtype - technically,
* this is breaking rest quite painfully!
*
* @name GET /api/v1/users/:userID/games/:game/:playtype/stats/custom
* @name GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom
*/
router.get("/custom", async (req, res) => {
const user = req[SYMBOL_TachiData]!.requestedUser!;
@@ -141,7 +141,7 @@ router.get("/custom", async (req, res) => {
/**
* Replaces a user's preferred stats.
*
* @name PUT /api/v1/users/:userID/games/:game/:playtype/stats
* @name PUT /api/v1/users/:userID/games/:game/:playtype/showcase
*/
router.put("/", RequireAuthedAsUser, RequirePermissions("customise_profile"), async (req, res) => {