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) + }) +})