[match] just a little cleanup

This commit is contained in:
Devin Zuczek
2026-08-12 14:24:59 -04:00
parent 36c30a396c
commit d3838fb590
2 changed files with 18 additions and 21 deletions
+13 -16
View File
@@ -136,22 +136,18 @@ function unauthorized(c: Context<App>) {
}
/**
* 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, unknown>): 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)
}
/**
+5 -5
View File
@@ -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 () => {