mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-14 01:59:05 +03:00
Merge pull request #635 from TNG-dev:zkldi/issue-634
Add support for bpiTargets in IIDX game settings.
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@
|
||||
"rimraf": "3.0.2",
|
||||
"safe-json-stringify": "1.2.0",
|
||||
"seq-logging": "^1.1.1",
|
||||
"tachi-common": "0.5.4",
|
||||
"tachi-common": "0.5.5",
|
||||
"ts-node": "10.0.0",
|
||||
"tsconfig-paths": "3.10.1",
|
||||
"typescript": "4.3.4",
|
||||
|
||||
Generated
+4
-4
@@ -63,7 +63,7 @@ specifiers:
|
||||
safe-json-stringify: 1.2.0
|
||||
seq-logging: ^1.1.1
|
||||
supertest: 6.1.3
|
||||
tachi-common: 0.5.4
|
||||
tachi-common: 0.5.5
|
||||
tap: 15.0.9
|
||||
ts-node: 10.0.0
|
||||
tsconfig-paths: 3.10.1
|
||||
@@ -107,7 +107,7 @@ dependencies:
|
||||
rimraf: 3.0.2
|
||||
safe-json-stringify: 1.2.0
|
||||
seq-logging: 1.1.1
|
||||
tachi-common: 0.5.4
|
||||
tachi-common: 0.5.5
|
||||
ts-node: 10.0.0_83f53b0a0c5616d3fa00ed4e30b9ce1b
|
||||
tsconfig-paths: 3.10.1
|
||||
typescript: 4.3.4
|
||||
@@ -5386,8 +5386,8 @@ packages:
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/tachi-common/0.5.4:
|
||||
resolution: {integrity: sha512-6QDpdvyGB2JOzPcW+7Hm/jXCKXXrIB6KgTKmvVq86771Iyali/oA2iigSb+oeVUQb8zNX2IM/s9hRD9F+80xTw==}
|
||||
/tachi-common/0.5.5:
|
||||
resolution: {integrity: sha512-LFKK+3xhlDQJ07yUij2/H+0cPiHXoXKdFQyR8X1ZNSjsluZoWncR9Rkqwhxlt/WeFBaGyLjkYkpdMkRYZMLVUg==}
|
||||
dependencies:
|
||||
monk: 7.3.4
|
||||
transitivePeerDependencies:
|
||||
|
||||
@@ -30,6 +30,7 @@ export async function CreateGameSettings(userID: integer, game: Game, playtype:
|
||||
if (game === "iidx") {
|
||||
gameSpecific = {
|
||||
display2DXTra: false,
|
||||
bpiTarget: 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,6 @@ t.test("#UpdateScore", (t) => {
|
||||
|
||||
const newScoreID = CreateScoreID(score.userID, score, score.chartID);
|
||||
|
||||
rootLogger.crit(newScoreID);
|
||||
|
||||
await db.imports.insert(mockImportDocument);
|
||||
await db.sessions.insert(mockSessionDocument);
|
||||
|
||||
@@ -87,8 +85,6 @@ t.test("#UpdateScore", (t) => {
|
||||
scoreID: newScoreID,
|
||||
});
|
||||
|
||||
rootLogger.crit("foo", await db.scores.find({}));
|
||||
|
||||
t.hasStrict(
|
||||
dbNewScore?.scoreData,
|
||||
score.scoreData,
|
||||
|
||||
@@ -42,6 +42,7 @@ t.test("#EvalulateUsersStatsShowcase", (t) => {
|
||||
],
|
||||
gameSpecific: {
|
||||
display2DXTra: false,
|
||||
bpiTarget: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+110
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import db from "external/mongo/db";
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
|
||||
@@ -102,6 +103,7 @@ t.test("PATCH /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
preferredScoreAlg: "ktLampRating",
|
||||
gameSpecific: {
|
||||
display2DXTra: true,
|
||||
bpiTarget: 50,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -119,6 +121,7 @@ t.test("PATCH /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
stats: [],
|
||||
gameSpecific: {
|
||||
display2DXTra: true,
|
||||
bpiTarget: 50,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -136,6 +139,113 @@ t.test("PATCH /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should update an IIDX player's bpiTarget settings.", (t) => {
|
||||
t.beforeEach(async () => {
|
||||
await db["api-tokens"].insert({
|
||||
userID: 1,
|
||||
identifier: "api_token",
|
||||
permissions: {
|
||||
customise_profile: true,
|
||||
},
|
||||
token: "api_token",
|
||||
fromAPIClient: null,
|
||||
});
|
||||
});
|
||||
|
||||
for (const target of [0, 10, 15, 100]) {
|
||||
t.test(`Should be able to update the BPI target to ${target}`, async (t) => {
|
||||
const res = await mockApi
|
||||
.patch("/api/v1/users/1/games/iidx/SP/settings")
|
||||
.set("Authorization", "Bearer api_token")
|
||||
.send({
|
||||
gameSpecific: {
|
||||
bpiTarget: target,
|
||||
},
|
||||
});
|
||||
|
||||
t.equal(res.statusCode, 200);
|
||||
|
||||
t.strictSame(
|
||||
res.body.body,
|
||||
{
|
||||
userID: 1,
|
||||
game: "iidx",
|
||||
playtype: "SP",
|
||||
preferences: {
|
||||
preferredScoreAlg: null,
|
||||
preferredSessionAlg: null,
|
||||
preferredProfileAlg: null,
|
||||
scoreBucket: null,
|
||||
stats: [],
|
||||
gameSpecific: {
|
||||
display2DXTra: false,
|
||||
bpiTarget: target,
|
||||
},
|
||||
},
|
||||
},
|
||||
"Should only update the mutated properties."
|
||||
);
|
||||
|
||||
const data = await db["game-settings"].findOne({
|
||||
userID: 1,
|
||||
game: "iidx",
|
||||
playtype: "SP",
|
||||
});
|
||||
|
||||
t.equal(data?.preferences.gameSpecific.bpiTarget, target);
|
||||
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
|
||||
t.test("Should reject float BPI targets.", async (t) => {
|
||||
const res = await mockApi
|
||||
.patch("/api/v1/users/1/games/iidx/SP/settings")
|
||||
.set("Authorization", "Bearer api_token")
|
||||
.send({
|
||||
gameSpecific: {
|
||||
bpiTarget: 10.5,
|
||||
},
|
||||
});
|
||||
|
||||
t.equal(res.statusCode, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should reject negative BPI targets", async (t) => {
|
||||
const res = await mockApi
|
||||
.patch("/api/v1/users/1/games/iidx/SP/settings")
|
||||
.set("Authorization", "Bearer api_token")
|
||||
.send({
|
||||
gameSpecific: {
|
||||
bpiTarget: -10,
|
||||
},
|
||||
});
|
||||
|
||||
t.equal(res.statusCode, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should reject >= 100 BPI targets", async (t) => {
|
||||
const res = await mockApi
|
||||
.patch("/api/v1/users/1/games/iidx/SP/settings")
|
||||
.set("Authorization", "Bearer api_token")
|
||||
.send({
|
||||
gameSpecific: {
|
||||
bpiTarget: 101,
|
||||
},
|
||||
});
|
||||
|
||||
t.equal(res.statusCode, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should reject a arbitrary things on game specific settings.", async (t) => {
|
||||
await db["api-tokens"].insert({
|
||||
userID: 1,
|
||||
|
||||
+4
-5
@@ -52,13 +52,12 @@ router.patch(
|
||||
|
||||
if (game === "iidx") {
|
||||
schema = {
|
||||
display2DXTra: "boolean",
|
||||
display2DXTra: p.optional("boolean"),
|
||||
bpiTarget: p.optional(p.isBoundedInteger(0, 100)),
|
||||
};
|
||||
}
|
||||
// A limitation in prudence means that validating top-level properties like this isn't
|
||||
// possible.
|
||||
// A prudence v1.0. should fix this!
|
||||
const err = p({ __: req.body.gameSpecific }, { __: p.optional(schema) }, {});
|
||||
|
||||
const err = p(req.body.gameSpecific, schema);
|
||||
|
||||
if (err) {
|
||||
return res.status(400).json({
|
||||
|
||||
+2
@@ -37,6 +37,7 @@ const SetFolders = async () => {
|
||||
],
|
||||
gameSpecific: {
|
||||
display2DXTra: false,
|
||||
bpiTarget: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -94,6 +95,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
|
||||
],
|
||||
gameSpecific: {
|
||||
display2DXTra: false,
|
||||
bpiTarget: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user