Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update player power upper limit #32

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ GOOGLE_APPLICATION_CREDENTIALS=""
DEFAULT_PROFILE_RATIO_VERSION="V1"
TW_PROFILE_RATIO_VERSION="V1"
JP_PROFILE_RATIO_VERSION="V2"
MIN_PROFILE_POWER="10000"
MAX_PROFILE_POWER="500000"
25 changes: 24 additions & 1 deletion src/commands/user/profile/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from "src/models/user-profile";
import { UserProfileStore } from "src/store/user-profiles";
import { defaultVersion } from "src/models/profile-ratio";
import { config } from "src/config";
import { logger } from "src/logger";
import { InteractiveCommand, NullOptionError } from "../../interactive-command";
import { CatchExecuteError } from "../../catch-execute-error";
import {
Expand All @@ -20,6 +22,27 @@ import {
OptionPowerOutOfRangeError,
} from "./update-errors";

const minProfilePower = parseInt(config.minProfilePower, 10);
const maxProfilePower = parseInt(config.maxProfilePower, 10);

if (isNaN(minProfilePower)) {
const msg = "invalid min profile power";
logger.fatal({ value: config.minProfilePower }, msg);
throw new Error(msg);
}

if (isNaN(maxProfilePower)) {
const msg = "invalid max profile power";
logger.fatal({ value: config.maxProfilePower }, msg);
throw new Error(msg);
}

if (minProfilePower > maxProfilePower) {
const msg = "min profile power is greater than max profile power";
logger.fatal({ minProfilePower, maxProfilePower }, msg);
throw new Error(msg);
}

interface UpdateProfileOptions {
type: UserProfileType;
power: number;
Expand Down Expand Up @@ -80,7 +103,7 @@ export class UpdateProfile extends InteractiveCommand {
if (isNaN(power)) {
throw new InvalidOptionPowerError();
}
if (power < 10000 || power > 350000) {
if (power < minProfilePower || power >= maxProfilePower) {
throw new OptionPowerOutOfRangeError();
}
return power;
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export const config = {
jpProfileRatioVersion: process.env.JP_PROFILE_RATIO_VERSION ?? "V2",
app: process.env.APP_NAME ?? "Hinomori",
logLevel: process.env.LOG_LEVEL ?? "debug",
minProfilePower: process.env.MIN_PROFILE_POWER ?? "10000",
maxProfilePower: process.env.MAX_PROFILE_POWER ?? "500000",
};
4 changes: 2 additions & 2 deletions test/commands/user/profile/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ describe("Profile Update Command", function () {
]);
});

it("should throw option power out of range error (> 350000)", async function () {
it("should throw option power out of range error (>= 500000)", async function () {
const stubInteraction = new StubInteraction()
.withOptionsGet("type", "r")
.withOptionsGet("power", 350001)
.withOptionsGet("power", 500000)
.withOptionsGet("cards", "130,100,80,80,60")
.withOptionsGet("index", undefined);

Expand Down