Skip to content

Commit ca111e4

Browse files
committed
fix: fixed special condition evolution parsing
1 parent d75fe6b commit ca111e4

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

__tests__/DexIntent.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,45 @@ describe('DexIntent', () => {
4444
`);
4545
});
4646

47+
test('GIVEN Pokémon with complicated evolutions THEN returns data with varying evos', async () => {
48+
expect.assertions(2);
49+
50+
const res = await fetch(SERVER)
51+
.post('/dexa')
52+
.send({
53+
request: {
54+
type: 'IntentRequest',
55+
intent: {
56+
name: 'DexIntent',
57+
slots: {
58+
POKEMON: {
59+
name: 'POKEMON',
60+
value: 'eevee'
61+
}
62+
}
63+
}
64+
}
65+
});
66+
67+
const { ssml } = res.body.response.outputSpeech;
68+
69+
expect(res.status).toBe(200);
70+
expect(ssml).toBe(oneLine`
71+
<speak>Eevee, number 133, Thanks to its unstable genetic makeup, this special Pokémon conceals many different possible evolutions.
72+
It is Normal type. It evolves into
73+
vaporeon (Special Condition: use Water Stone) and
74+
jolteon (Special Condition: use Thunder Stone) and
75+
flareon (Special Condition: use Fire Stone) and
76+
espeon (Special Condition: Level up during Daytime with High Friendship) and
77+
umbreon (Special Condition: Level up during Nighttime with High Friendship) and
78+
leafeon (Special Condition: use Leaf Stone) and
79+
glaceon (Special Condition: use Ice Stone) and
80+
sylveon (Special Condition: Level up while having high Affection and knowing a Fairy type move).
81+
Eevee is typically 0.3 meters tall and weighs about 6.5 kilograms.
82+
It has a gender ratio of 87.5% male and 12.5% female.</speak>
83+
`);
84+
});
85+
4786
test('GIVEN Pokémon with pre-evolution and evolution THEN returns data with prevo and evo', async () => {
4887
expect.assertions(2);
4988

src/constants.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ export const parsePrevos = (data: DexDetails) => {
123123

124124
export const parseEvos = (data: DexDetails) => {
125125
const evos: string[] = [];
126-
const hasEvoByLevel = (evolutionMethod: string) => Number(evolutionMethod);
126+
const hasEvoByLevel = (evolutionMethod: string | null | undefined) => Number(evolutionMethod);
127127

128128
data.evolutions!.forEach(evo => {
129-
evos.push(`${evo.species} ${hasEvoByLevel ? `(Level: ${evo.evolutionLevel})` : `(Special Condition: ${evo.evolutionLevel})`}`);
129+
evos.push(
130+
[
131+
`${evo.species}`,
132+
`${hasEvoByLevel(evo.evolutionLevel) ? `(Level: ${evo.evolutionLevel})` : `(Special Condition: ${evo.evolutionLevel})`}`
133+
].join(' ')
134+
);
130135

131136
if (evo.evolutions) {
132137
evo.evolutions.forEach(evvo => {
133-
evos.push(`${evvo.species} ${hasEvoByLevel ? `(Level: ${evvo.evolutionLevel})` : `(Special Condition: ${evvo.evolutionLevel})`}`);
138+
evos.push(
139+
[
140+
`${evvo.species}`,
141+
`${hasEvoByLevel(evvo.evolutionLevel) ? `(Level: ${evvo.evolutionLevel})` : `(Special Condition: ${evvo.evolutionLevel})`}`
142+
].join(' ')
143+
);
134144
});
135145
}
136146
});

0 commit comments

Comments
 (0)