From d3838fb5909b430b2d51eff70ac888f25ba43f3e Mon Sep 17 00:00:00 2001 From: Devin Zuczek Date: Wed, 12 Aug 2026 14:24:59 -0400 Subject: [PATCH] [match] just a little cleanup --- apps/match/src/match.app.ts | 29 +++++++++------------ apps/match/src/test/integration/api.test.ts | 10 +++---- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/apps/match/src/match.app.ts b/apps/match/src/match.app.ts index 01af585..2393071 100644 --- a/apps/match/src/match.app.ts +++ b/apps/match/src/match.app.ts @@ -136,22 +136,18 @@ function unauthorized(c: Context) { } /** - * The "avoid juniors" preference, normalized. The player's settings are a free-form - * `{ key: value }` bag written by the client through the `playersettings` worker, and the - * exact spelling it writes this key under is reverse-engineered — so the lookup is - * case- and separator-insensitive (`AvoidJuniors`, `avoidjuniors`, `AVOID_JUNIORS` all - * resolve to this one preference) rather than betting on one casing and silently reading - * false forever if it's wrong. + * The "avoid juniors" preference, spelled the way the client posts it — the key a NEW + * setting is written under, and the one every stored spelling is matched against. + * + * The player's settings are a free-form `{ key: value }` bag written by the client through + * the `playersettings` worker, and the exact spelling it writes this key under is + * reverse-engineered, so the lookup is case- and separator-insensitive (`avoidJuniors`, + * `AvoidJuniors`, `AVOID_JUNIORS` all resolve to this one preference) rather than betting on + * one casing and silently reading false forever if it's wrong. The write then overwrites + * whichever spelling is already there, so a player never ends up with two keys for the one + * preference — which would make the read depend on their order in the map. */ -const AVOID_JUNIORS_SETTING = 'avoidjuniors' - -/** - * The spelling a NEW setting is written under. Only used when the player's map doesn't - * already carry the key under some other spelling — the write overwrites whichever one is - * there, so a player never ends up with two keys for the one preference (which would make - * the read depend on their order in the map). - */ -const AVOID_JUNIORS_KEY = 'AvoidJuniors' +const AVOID_JUNIORS_KEY = 'avoidJuniors' /** Lowercase and drop separators, so keys compare on their letters alone. */ function normalizeSettingKey(key: string): string { @@ -160,7 +156,8 @@ function normalizeSettingKey(key: string): string { /** The player's existing spelling of the setting key, if their map has one. */ function findAvoidJuniorsKey(stored: Record): string | undefined { - return Object.keys(stored).find((key) => normalizeSettingKey(key) === AVOID_JUNIORS_SETTING) + const wanted = normalizeSettingKey(AVOID_JUNIORS_KEY) + return Object.keys(stored).find((key) => normalizeSettingKey(key) === wanted) } /** diff --git a/apps/match/src/test/integration/api.test.ts b/apps/match/src/test/integration/api.test.ts index 0474be4..7bac901 100644 --- a/apps/match/src/test/integration/api.test.ts +++ b/apps/match/src/test/integration/api.test.ts @@ -294,10 +294,10 @@ describe('public endpoints', () => { } test('reads the stored setting', async () => { - await settings(3100, { AvoidJuniors: 'True', 'Recroom.OOBE': '77' }) + await settings(3100, { avoidJuniors: 'True', 'Recroom.OOBE': '77' }) expect(await read(3100)).toBe(true) - await settings(3101, { AvoidJuniors: 'False' }) + await settings(3101, { avoidJuniors: 'False' }) expect(await read(3101)).toBe(false) }) @@ -317,7 +317,7 @@ describe('public endpoints', () => { await settings(3105, { 'Recroom.OOBE': '77' }) expect(await read(3105)).toBe(false) - await settings(3106, { AvoidJuniors: 'maybe' }) + await settings(3106, { avoidJuniors: 'maybe' }) expect(await read(3106)).toBe(false) }) @@ -370,7 +370,7 @@ describe('public endpoints', () => { expect(await stored(3201)).toEqual({ 'Recroom.OOBE': '77', TUTORIAL_COMPLETE_MASK: '11', - AvoidJuniors: 'True', + avoidJuniors: 'True', }) }) @@ -405,7 +405,7 @@ describe('public endpoints', () => { await write(3204, 'avoidJuniors=True') expect(await write(3204, 'avoidJuniors=maybe')).toBe(true) expect(await write(3204, '')).toBe(true) - expect(await stored(3204)).toEqual({ AvoidJuniors: 'True' }) + expect(await stored(3204)).toEqual({ avoidJuniors: 'True' }) }) test('is auth-gated', async () => {