mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-27 22:21:07 +00:00
Clan System Part 1 (#3276)
## 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
This commit is contained in:
+59
-175
@@ -1,215 +1,99 @@
|
||||
import { PlayerInfo, PlayerType } from "../src/core/game/Game";
|
||||
|
||||
describe("PlayerInfo", () => {
|
||||
describe("clan", () => {
|
||||
test("should extract clan from name when format contains [XX]", () => {
|
||||
describe("clanTag from explicit clanTag parameter", () => {
|
||||
test("should set clanTag from clanTag parameter", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[CL]PlayerName",
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
"abc",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("CL");
|
||||
expect(playerInfo.clanTag).toBe("abc");
|
||||
});
|
||||
|
||||
test("should extract clan from name when format contains [XXX]", () => {
|
||||
test("should preserve already-uppercase clan tag", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[ABC]PlayerName",
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
"CLAN",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("ABC");
|
||||
expect(playerInfo.clanTag).toBe("CLAN");
|
||||
});
|
||||
|
||||
test("should extract clan from name when format contains [XXXX]", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[ABCD]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("ABCD");
|
||||
});
|
||||
|
||||
test("should extract clan from name when format contains [XXXXX]", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[ABCDE]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("ABCDE");
|
||||
});
|
||||
|
||||
test("should extract uppercase clan from name when format contains [xxxxx]", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[abcde]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("ABCDE");
|
||||
});
|
||||
|
||||
test("should extract uppercase clan from name when format contains [XxXxX]", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[AbCdE]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("ABCDE");
|
||||
});
|
||||
|
||||
test("should extract uppercase clan from name when format contains [Xx#xX]", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[Ab1cD]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("AB1CD");
|
||||
});
|
||||
|
||||
test("should return null when name doesn't contain [", () => {
|
||||
test("should set clan to null when clanTag is not provided", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBeNull();
|
||||
expect(playerInfo.clanTag).toBeNull();
|
||||
});
|
||||
|
||||
test("should return null when name doesn't contain ]", () => {
|
||||
test("should set clan to null when clanTag is null", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[ABCPlayerName",
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
null,
|
||||
);
|
||||
expect(playerInfo.clanTag).toBeNull();
|
||||
});
|
||||
|
||||
test("should set clan to null when clanTag is undefined", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
undefined,
|
||||
);
|
||||
expect(playerInfo.clanTag).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("displayName", () => {
|
||||
test("should construct display name with clan tag", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
"CLAN",
|
||||
);
|
||||
expect(playerInfo.displayName).toBe("[CLAN] PlayerName");
|
||||
});
|
||||
|
||||
test("should return just name when no clan tag", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBeNull();
|
||||
expect(playerInfo.displayName).toBe("PlayerName");
|
||||
});
|
||||
|
||||
test("should return null when clan tag is not 2-5 alphanumeric letters", () => {
|
||||
test("should preserve clan tag casing in display name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[A]PlayerName",
|
||||
"PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
false,
|
||||
"abc",
|
||||
);
|
||||
expect(playerInfo.clan).toBeNull();
|
||||
});
|
||||
|
||||
test("should return null when clan tag contains non alphanumeric characters", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[A?c]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBeNull();
|
||||
});
|
||||
|
||||
test("should return null when clan tag is too long", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[ABCDEF]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBeNull();
|
||||
});
|
||||
|
||||
test("should extract uppercase clan name from any location in the player name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"Player[aa]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("AA");
|
||||
});
|
||||
|
||||
test("should extract only the first occurrence of a clan name match", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[Ab1cD]Player[aa]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("AB1CD");
|
||||
});
|
||||
|
||||
test("should extract only the first occurrence of a valid clan name match and extract as uppercase", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[Ab1cDEF]Player[aa]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("AA");
|
||||
});
|
||||
|
||||
test("should extract numeric-only clan names", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[012]PlayerName",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("012");
|
||||
});
|
||||
|
||||
test("should extract numeric-only clan names and only the first valid clan name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"[012]Player[aa]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("012");
|
||||
});
|
||||
|
||||
test("should extract numeric-only clan names from anywhere within the name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"Player[012]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("012");
|
||||
});
|
||||
|
||||
test("should extract numeric-only clan names from the end of the name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName[012]",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("012");
|
||||
});
|
||||
|
||||
test("should extract uppercase alphanumeric clan names from anywhere within the name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"Player[0a1B2]Name",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("0A1B2");
|
||||
});
|
||||
|
||||
test("should extract uppercase alphanumeric clan names from the end of the name", () => {
|
||||
const playerInfo = new PlayerInfo(
|
||||
"PlayerName[0a1B2]",
|
||||
PlayerType.Human,
|
||||
null,
|
||||
"player_id",
|
||||
);
|
||||
expect(playerInfo.clan).toBe("0A1B2");
|
||||
expect(playerInfo.displayName).toBe("[abc] PlayerName");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user