fix(server,stage-tamagotchi): restore ofetch-compatible Steam tests and zod notice placement

This commit is contained in:
Lulu
2026-08-07 23:25:46 +08:00
parent fb0d1ecce1
commit 641d043c25
3 changed files with 21 additions and 21 deletions
@@ -62,6 +62,6 @@ describe('exchangeSteamTicketForTokens', () => {
throw new Error('offline')
}) as unknown as typeof fetch
const result = await exchangeSteamTicketForTokens({ serverUrl: 'https://api.airi.build', ticketHex: 'deadbeef' })
expect(result).toEqual({ ok: false, reason: 'offline' })
expect(result).toEqual({ ok: false, reason: expect.stringContaining('offline') })
})
})
@@ -12,14 +12,6 @@ const STEAM_OPENID_IDENTIFIER_SELECT = 'http://specs.openid.net/auth/2.0/identif
/** Matches `https://steamcommunity.com/openid/id/<steamid64>`. */
const STEAM_CLAIMED_ID_PATTERN = /^https:\/\/steamcommunity\.com\/openid\/id\/(\d{17})$/
// NOTICE:
// Why Zod instead of the repo-default Valibot: better-auth's endpoint API and
// OpenAPI generator are Zod-native. The generator introspects
// `instanceof z.ZodObject` on `body`/`query` to emit request/query schemas
// (node_modules/better-auth/dist/plugins/open-api/generator.mjs), so Valibot
// schemas would validate at runtime (better-call uses Standard Schema) but
// silently drop those OpenAPI fields. Keep these schemas in Zod until
// better-auth's OpenAPI generation supports non-Zod schemas.
/**
* The slice of better-auth's `internalAdapter` that {@link resolveOrCreateSteamUser}
* needs.
@@ -74,6 +66,14 @@ export async function resolveOrCreateSteamUser(
return { userId: user.id }
}
// NOTICE:
// Why Zod instead of the repo-default Valibot: better-auth's endpoint API and
// OpenAPI generator are Zod-native. The generator introspects
// `instanceof z.ZodObject` on `body`/`query` to emit request/query schemas
// (node_modules/better-auth/dist/plugins/open-api/generator.mjs), so Valibot
// schemas would validate at runtime (better-call uses Standard Schema) but
// silently drop those OpenAPI fields. Keep these schemas in Zod until
// better-auth's OpenAPI generation supports non-Zod schemas.
const SignInBodySchema = z.object({
callbackURL: z.string().meta({ description: 'The URL to redirect to after sign in' }),
errorCallbackURL: z.string().meta({ description: 'The URL to redirect to if an error occurs' }).optional(),
@@ -6,12 +6,12 @@ describe('authenticateUserTicket', () => {
afterEach(() => vi.restoreAllMocks())
it('returns steamid when Steam API reports success', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
response: { params: { result: 'OK', steamid: '76561198000000000' } },
}),
}))
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
response: { params: { result: 'OK', steamid: '76561198000000000' } },
}), {
status: 200,
headers: { 'content-type': 'application/json' },
})))
const steamId = await authenticateUserTicket({
publisherKey: 'test-key',
@@ -23,12 +23,12 @@ describe('authenticateUserTicket', () => {
})
it('throws when result is not OK', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
response: { params: { result: 'InvalidTicket' } },
}),
}))
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
response: { params: { result: 'InvalidTicket' } },
}), {
status: 200,
headers: { 'content-type': 'application/json' },
})))
await expect(authenticateUserTicket({
publisherKey: 'test-key',