mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 20:16:44 +00:00
1049b7e7dc
## Description: Properly split out clantags and usernames, a clantag should not be part of a username. <img width="285" height="286" alt="image" src="https://github.com/user-attachments/assets/8ac56e82-b12c-4fc0-9774-e445252a6e61" /> https://api.openfront.dev/game/ojkqZFb2 <img width="296" height="596" alt="image" src="https://github.com/user-attachments/assets/85152f80-c111-4f87-b85b-8516c9c6137b" /> https://api.openfront.dev/game/MF32BkVc requires; https://github.com/openfrontio/infra/pull/264 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
// Mocks the output of translation functions to return predictable values.
|
|
vi.mock("../src/client/Utils", () => ({
|
|
translateText: (key: string, vars?: any) =>
|
|
vars ? `${key}:${JSON.stringify(vars)}` : key,
|
|
}));
|
|
|
|
import {
|
|
MAX_CLAN_TAG_LENGTH,
|
|
MAX_USERNAME_LENGTH,
|
|
validateClanTag,
|
|
validateUsername,
|
|
} from "../src/core/validations/username";
|
|
|
|
describe("username.ts functions", () => {
|
|
describe("validateUsername", () => {
|
|
test("rejects non-string", () => {
|
|
// @ts-expect-error: Testing non-string input to validateUsername on purpose
|
|
const res = validateUsername(123);
|
|
expect(res.isValid).toBe(false);
|
|
expect(res.error).toBeDefined();
|
|
});
|
|
test("rejects too short", () => {
|
|
const res = validateUsername("ab");
|
|
expect(res.isValid).toBe(false);
|
|
});
|
|
test("rejects too long", () => {
|
|
const long = "a".repeat(MAX_USERNAME_LENGTH + 1);
|
|
const res = validateUsername(long);
|
|
expect(res.isValid).toBe(false);
|
|
});
|
|
test("rejects invalid chars", () => {
|
|
const res = validateUsername("Invalid!Name");
|
|
expect(res.isValid).toBe(false);
|
|
});
|
|
test("accepts valid ASCII names", () => {
|
|
const res = validateUsername("Good_Name123");
|
|
expect(res.isValid).toBe(true);
|
|
});
|
|
test("accepts allowed Unicode like ü", () => {
|
|
const res = validateUsername("Üser");
|
|
expect(res.isValid).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("validateClanTag", () => {
|
|
test("accepts empty clan tag", () => {
|
|
const res = validateClanTag("");
|
|
expect(res.isValid).toBe(true);
|
|
});
|
|
|
|
test("rejects too short clan tag", () => {
|
|
const res = validateClanTag("A");
|
|
expect(res.isValid).toBe(false);
|
|
expect(res.error).toBe("username.tag_too_short");
|
|
});
|
|
|
|
test("rejects invalid clan tag characters", () => {
|
|
const res = validateClanTag("A!");
|
|
expect(res.isValid).toBe(false);
|
|
expect(res.error).toBe("username.tag_invalid_chars");
|
|
});
|
|
|
|
test("rejects too long clan tag", () => {
|
|
const res = validateClanTag("A".repeat(MAX_CLAN_TAG_LENGTH + 1));
|
|
expect(res.isValid).toBe(false);
|
|
expect(res.error).toBe("username.tag_too_short");
|
|
});
|
|
|
|
test("accepts valid clan tag", () => {
|
|
const res = validateClanTag("AB12");
|
|
expect(res.isValid).toBe(true);
|
|
});
|
|
});
|
|
});
|