From 080bd93efca6a59a2277387309ee27111923b50b Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Wed, 22 Apr 2026 05:04:16 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85=20hatchEgg=20?= =?UTF-8?q?=E5=92=8C=20species=20=E8=A1=A5=E5=85=85=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=88227=E2=86=92237=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - egg.test.ts: 新增 hatchEgg 5 个测试 - 创建 creature 并移除 egg - 放入 party 空位 - totalEggsObtained 计数 - 新 species dex entry 创建 - 已有 species caughtCount 递增 - species.test.ts: 新增 ensureSpeciesData、baseHappiness、captureRate、names、shinyChance 测试 Co-Authored-By: Claude Opus 4.6 --- packages/pokemon/src/__tests__/egg.test.ts | 47 ++++++++++++++++++- .../pokemon/src/__tests__/species.test.ts | 28 ++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/packages/pokemon/src/__tests__/egg.test.ts b/packages/pokemon/src/__tests__/egg.test.ts index 723fefe02..6cc8b3305 100644 --- a/packages/pokemon/src/__tests__/egg.test.ts +++ b/packages/pokemon/src/__tests__/egg.test.ts @@ -1,5 +1,5 @@ import { describe, test, expect } from 'bun:test' -import { checkEggEligibility, generateEgg, advanceEggSteps, isEggReadyToHatch } from '../core/egg' +import { checkEggEligibility, generateEgg, advanceEggSteps, isEggReadyToHatch, hatchEgg } from '../core/egg' import type { BuddyData } from '../types' import { generateCreature } from '../core/creature' @@ -113,3 +113,48 @@ describe('isEggReadyToHatch', () => { expect(isEggReadyToHatch(egg)).toBe(false) }) }) + +describe('hatchEgg', () => { + test('creates a creature and removes egg', async () => { + const data = makeBuddyData() + const egg = { id: 'egg-1', obtainedAt: Date.now(), stepsRemaining: 0, totalSteps: 2000, speciesId: 'charmander' as const } + const result = await hatchEgg(data, egg) + + expect(result.creature.speciesId).toBe('charmander') + expect(result.buddyData.creatures.length).toBe(data.creatures.length + 1) + expect(result.buddyData.eggs.length).toBe(0) + }) + + test('adds creature to party when slot available', async () => { + const data = makeBuddyData() + const egg = { id: 'egg-1', obtainedAt: Date.now(), stepsRemaining: 0, totalSteps: 2000, speciesId: 'pikachu' as const } + const result = await hatchEgg(data, egg) + const newCreature = result.creature + const inParty = result.buddyData.party.includes(newCreature.id) + expect(inParty).toBe(true) + }) + + test('increments totalEggsObtained', async () => { + const data = makeBuddyData() + const egg = { id: 'egg-1', obtainedAt: Date.now(), stepsRemaining: 0, totalSteps: 2000, speciesId: 'squirtle' as const } + const result = await hatchEgg(data, egg) + expect(result.buddyData.stats.totalEggsObtained).toBe(1) + }) + + test('updates dex entry with new species', async () => { + const data = makeBuddyData() + const egg = { id: 'egg-1', obtainedAt: Date.now(), stepsRemaining: 0, totalSteps: 2000, speciesId: 'charmander' as const } + const result = await hatchEgg(data, egg) + const entry = result.buddyData.dex.find(d => d.speciesId === 'charmander') + expect(entry).toBeDefined() + expect(entry!.caughtCount).toBe(1) + }) + + test('increments caughtCount for existing dex entry', async () => { + const data = makeBuddyData() + const egg = { id: 'egg-1', obtainedAt: Date.now(), stepsRemaining: 0, totalSteps: 2000, speciesId: 'bulbasaur' as const } + const result = await hatchEgg(data, egg) + const entry = result.buddyData.dex.find(d => d.speciesId === 'bulbasaur') + expect(entry!.caughtCount).toBe(2) + }) +}) diff --git a/packages/pokemon/src/__tests__/species.test.ts b/packages/pokemon/src/__tests__/species.test.ts index e6ea5db6e..c12eef47a 100644 --- a/packages/pokemon/src/__tests__/species.test.ts +++ b/packages/pokemon/src/__tests__/species.test.ts @@ -1,5 +1,5 @@ import { describe, test, expect } from 'bun:test' -import { getSpeciesData, getAllSpeciesData, DEX_TO_SPECIES } from '../data/species' +import { getSpeciesData, getAllSpeciesData, DEX_TO_SPECIES, ensureSpeciesData } from '../data/species' import { ALL_SPECIES_IDS } from '../types' import type { SpeciesId } from '../types' @@ -67,3 +67,29 @@ describe('DEX_TO_SPECIES', () => { expect(DEX_TO_SPECIES[25]).toBe('pikachu') }) }) + +describe('ensureSpeciesData', () => { + test('resolves without error', async () => { + await expect(ensureSpeciesData()).resolves.toBeUndefined() + }) +}) + +describe('getSpeciesData - supplementary fields', () => { + test('has baseHappiness', () => { + expect(getSpeciesData('bulbasaur').baseHappiness).toBe(70) + }) + + test('pikachu has higher captureRate', () => { + expect(getSpeciesData('pikachu').captureRate).toBeGreaterThan(getSpeciesData('charmander').captureRate) + }) + + test('has names with en key', () => { + const data = getSpeciesData('charmander') + expect(data.names).toBeDefined() + expect(data.names.en).toBe('Charmander') + }) + + test('shinyChance is 1/4096', () => { + expect(getSpeciesData('bulbasaur').shinyChance).toBe(1 / 4096) + }) +})