Skip to content

Commit

Permalink
fix: fixed special condition evolution parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Jan 5, 2020
1 parent d75fe6b commit ca111e4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
39 changes: 39 additions & 0 deletions __tests__/DexIntent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<speak>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.</speak>
`);
});

test('GIVEN Pokémon with pre-evolution and evolution THEN returns data with prevo and evo', async () => {
expect.assertions(2);

Expand Down
16 changes: 13 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
);
});
}
});
Expand Down

0 comments on commit ca111e4

Please sign in to comment.