diff --git a/__tests__/DexIntent.test.ts b/__tests__/DexIntent.test.ts index af8c969..57488df 100644 --- a/__tests__/DexIntent.test.ts +++ b/__tests__/DexIntent.test.ts @@ -44,6 +44,45 @@ describe('DexIntent', () => { `); }); + test('GIVEN Pokémon with complicated evolutions THEN returns data with varying evos', async () => { + expect.assertions(2); + + const res = await fetch(SERVER) + .post('/dexa') + .send({ + request: { + type: 'IntentRequest', + intent: { + name: 'DexIntent', + slots: { + POKEMON: { + name: 'POKEMON', + value: 'eevee' + } + } + } + } + }); + + const { ssml } = res.body.response.outputSpeech; + + expect(res.status).toBe(200); + expect(ssml).toBe(oneLine` + Eevee, number 133, Thanks to its unstable genetic makeup, this special Pokémon conceals many different possible evolutions. + It is Normal type. It evolves into + vaporeon (Special Condition: use Water Stone) and + jolteon (Special Condition: use Thunder Stone) and + flareon (Special Condition: use Fire Stone) and + espeon (Special Condition: Level up during Daytime with High Friendship) and + umbreon (Special Condition: Level up during Nighttime with High Friendship) and + leafeon (Special Condition: use Leaf Stone) and + glaceon (Special Condition: use Ice Stone) and + sylveon (Special Condition: Level up while having high Affection and knowing a Fairy type move). + Eevee is typically 0.3 meters tall and weighs about 6.5 kilograms. + It has a gender ratio of 87.5% male and 12.5% female. + `); + }); + test('GIVEN Pokémon with pre-evolution and evolution THEN returns data with prevo and evo', async () => { expect.assertions(2); diff --git a/src/constants.ts b/src/constants.ts index 73c1d03..5417961 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -123,14 +123,24 @@ export const parsePrevos = (data: DexDetails) => { export const parseEvos = (data: DexDetails) => { const evos: string[] = []; - const hasEvoByLevel = (evolutionMethod: string) => Number(evolutionMethod); + const hasEvoByLevel = (evolutionMethod: string | null | undefined) => Number(evolutionMethod); data.evolutions!.forEach(evo => { - evos.push(`${evo.species} ${hasEvoByLevel ? `(Level: ${evo.evolutionLevel})` : `(Special Condition: ${evo.evolutionLevel})`}`); + evos.push( + [ + `${evo.species}`, + `${hasEvoByLevel(evo.evolutionLevel) ? `(Level: ${evo.evolutionLevel})` : `(Special Condition: ${evo.evolutionLevel})`}` + ].join(' ') + ); if (evo.evolutions) { evo.evolutions.forEach(evvo => { - evos.push(`${evvo.species} ${hasEvoByLevel ? `(Level: ${evvo.evolutionLevel})` : `(Special Condition: ${evvo.evolutionLevel})`}`); + evos.push( + [ + `${evvo.species}`, + `${hasEvoByLevel(evvo.evolutionLevel) ? `(Level: ${evvo.evolutionLevel})` : `(Special Condition: ${evvo.evolutionLevel})`}` + ].join(' ') + ); }); } });