Skip to content
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
12 changes: 12 additions & 0 deletions packages/raiderio/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createRaiderIoClient } from "./index";
type FixtureName =
| "character-visible-owner"
| "character-private-owner"
| "character-empty-discord"
| "character-declared-main"
| "character-declared-main-out-of-scope"
| "character-renamed-root"
Expand Down Expand Up @@ -166,6 +167,17 @@ describe("Raider.IO gateway", () => {
expect(character.profileGuess).toBe("profile-candidate");
});

it("treats an empty customization field as absent, not as schema drift", async () => {
// Break caught: Raider.IO sends "" for a customization a player never set.
// Rejecting it raised non-retryable schema_drift, so every character with an
// empty Discord field failed its search permanently.
const character = await clientFor("character-empty-discord").getCharacter(
sentinel
);

expect(character.profileGuess).toBeNull();
});

it("extracts and normalizes a declared-main character key", async () => {
const character = await clientFor("character-declared-main").getCharacter(
sentinel
Expand Down
7 changes: 5 additions & 2 deletions packages/raiderio/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const characterResponseSchema = z.object({
.optional(),
characterCustomizations: z
.object({
discord_profile: z.string().min(1).nullable().optional(),
// Raider.IO sends "" for a customization the player never set. That is
// an absent value, not structural change: rejecting it would raise
// non-retryable schema drift and permanently fail the search.
discord_profile: z.string().nullable().optional(),
main_character: declaredMainSchema.nullable().optional()
})
.optional()
Expand Down Expand Up @@ -147,7 +150,7 @@ export function normalizeCharacterResponse(
return {
...character,
ownerId: details.user?.name ?? null,
profileGuess: customizations?.discord_profile ?? null,
profileGuess: customizations?.discord_profile?.trim() || null,
declaredMain,
...(omittedMembers ? { omittedMembers: true } : {})
};
Expand Down
21 changes: 21 additions & 0 deletions tests/fixtures/raiderio/character-empty-discord.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"status": 200,
"body": {
"characterDetails": {
"character": {
"name": "Sentinel",
"level": 90,
"class": { "name": "Paladin" },
"realm": { "slug": "Silvermoon" },
"region": { "slug": "EU" }
},
"user": null,
"characterCustomizations": {
"isClaimed": false,
"biography": "",
"discord_profile": "",
"main_character": null
}
}
}
}
Loading