Skip to content

Commit

Permalink
fix: multiple bugfixes, details in description
Browse files Browse the repository at this point in the history
- Fixed that prevos would not get their evolution method parsed
correctly
- Fixed that prevos and evos were not parsed to Titlecase
- Covered more special cases in unit tests
  - Regional forms with non-regional pre-evo
  - Regional forms with regional pre-evos
  - Gigantamax forms
  - Mega forms
- Covered error case in individual file

- build: Changed test runner to jest-circus for automatic retries
- test: moved server setup to global Jest setup file
  • Loading branch information
favna committed Jan 6, 2020
1 parent f55f6d0 commit 73ef48b
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 72 deletions.
10 changes: 1 addition & 9 deletions __tests__/AbilityIntent.test.ts
@@ -1,16 +1,8 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';
import { SERVER } from './utils';

describe('AbilityIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Ability THEN returns data', async () => {
expect.assertions(2);

Expand Down
184 changes: 154 additions & 30 deletions __tests__/DexIntent.test.ts
@@ -1,16 +1,8 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';
import { SERVER } from './utils';

describe('DexIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Pokémon with evolutions THEN returns data with prevos', async () => {
expect.assertions(2);

Expand Down Expand Up @@ -38,7 +30,7 @@ describe('DexIntent', () => {
<speak>Dragonite, number 149, It is said that this Pokémon lives somewhere in the sea and that it flies.
However, these are only rumors.
It is Dragon Flying type.
Its pre-evolutions are dragonair (Level: 55) and dratini (Level: 30).
Its pre-evolutions are Dragonair (Level: 55) and Dratini (Level: 30).
Dragonite is typically 2.2 meters tall and weighs about 210 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
Expand Down Expand Up @@ -70,14 +62,14 @@ describe('DexIntent', () => {
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).
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>
`);
Expand Down Expand Up @@ -110,8 +102,8 @@ describe('DexIntent', () => {
<speak>Dragonair, number 148, According to a witness, its body was surrounded by a strange aura that gave it a
mystical look.
It is Dragon type.
Its pre-evolution is dratini (Level: 30).
It evolves into dragonite (Level: 55).
Its pre-evolution is Dratini (Level: 30).
It evolves into Dragonite (Level: 55).
Dragonair is typically 4 meters tall and weighs about 16.5 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
Expand Down Expand Up @@ -144,7 +136,7 @@ describe('DexIntent', () => {
<speak>Dratini, number 147, Long thought to be a myth, this Pokémon's existence was only recently confirmed by a
fisherman who caught one.
It is Dragon type.
It evolves into dragonair (Level: 30) and dragonite (Level: 55).
It evolves into Dragonair (Level: 30) and Dragonite (Level: 55).
Dratini is typically 1.8 meters tall and weighs about 3.3 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
Expand Down Expand Up @@ -209,15 +201,15 @@ describe('DexIntent', () => {
<speak>Metagross, number 376, It analyzes its opponents with more accuracy than a supercomputer,
which enables it to calmly back them into a corner.
It is Steel Psychic type.
Its pre-evolutions are metang (Level: 45) and beldum (Level: 20).
Its pre-evolutions are
Metang (Level: 45) and
Beldum (Level: 20).
Metagross is typically 1.6 meters tall and weighs about 550 kilograms.
It is genderless.</speak>
`);
});

test('GIVEN invalid data THEN returns error response', async () => {
// Mocking out the GraphQL warning response
jest.spyOn(console, 'warn').mockImplementationOnce(() => undefined);
test('GIVEN a gmax Pokemon THEN returns gmax information', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
Expand All @@ -230,7 +222,7 @@ describe('DexIntent', () => {
slots: {
POKEMON: {
name: 'POKEMON',
value: 'aklsjdkjlashgdjlhaksgdjaghsdghasjd'
value: 'gigantamax charizard'
}
}
}
Expand All @@ -241,9 +233,141 @@ describe('DexIntent', () => {

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>I am sorry but I could not resolve that query.
I think you said aklsjdkjlashgdjlhaksgdjaghsdghasjd?
Maybe try again, or respond with \"Alexa Cancel\" if you want to stop.</speak>
`);
<speak>Charizard-gmax, number 6, The flame inside its body burns hotter than 3,600 degrees Fahrenheit.
When Charizard roars, that temperature climbs even higher.
It is Fire Flying type.
Charizard-gmax is typically 28 meters tall and weighs about 100.5 kilograms.
It has a gender ratio of 87.5% male and 12.5% female.</speak>
`);
});

test('GIVEN a mega Pokemon THEN returns mega information', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'mega metagross'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>Metagross-mega, number 376, When it knows it can't win,
it digs the claws on its legs into its opponent and starts the countdown to a big explosion.
It is Steel Psychic type.
Metagross-mega is typically 2.5 meters tall and weighs about 942.9 kilograms.
It is genderless.</speak>
`);
});

test('GIVEN an alolan forme Pokemon THEN returns alolan information', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'alolan sandshrew'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>Sandshrew-alola, number 27, Its ice-covered body lets it slide across the ground with bullet-like speed,
sending its enemies flying when it hits them.
It is Ice Steel type.
It evolves into Sandslash-alola (Special Condition: use Icestone).
Sandshrew-alola is typically 0.7 meters tall and weighs about 40 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
});

test('GIVEN a galarian forme Pokemon THEN returns galarian information', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'galarian ponyta'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>Ponyta-galar, number 77, This Pokémon will look into your eyes and read the contents of your heart.
If it finds evil there, it promptly hides away.
It is Psychic type. It evolves into Rapidash-galar (Level: 40).
Ponyta-galar is typically 0.8 meters tall and weighs about 24 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
});

test('GIVEN an alolan forme evolution Pokemon THEN returns mixed information', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'alolan raichu'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>Raichu-alola, number 26, This Pokémon rides on its tail while it uses its psychic powers to levitate.
It attacks with star-shaped thunderbolts.
It is Electric Psychic type.
Its pre-evolutions are Pikachu (Special Condition: use Thunder Stone) and Pichu (Special Condition: Level up with High Friendship).
Raichu-alola is typically 0.7 meters tall and weighs about 21 kilograms.
It has a gender ratio of 50% male and 50% female.</speak>
`);
});
});
37 changes: 37 additions & 0 deletions __tests__/ErrorHandling.test.ts
@@ -0,0 +1,37 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER } from './utils';

describe('ItemIntent', () => {
test('GIVEN invalid data THEN returns error response', async () => {
// Mocking out the GraphQL warning response
jest.spyOn(console, 'warn').mockImplementationOnce(() => undefined);
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'aklsjdkjlashgdjlhaksgdjaghsdghasjd'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>I am sorry but I could not resolve that query.
I think you said aklsjdkjlashgdjlhaksgdjaghsdghasjd?
Maybe try again, or respond with \"Alexa Cancel\" if you want to stop.</speak>
`);
});
});
10 changes: 1 addition & 9 deletions __tests__/ItemIntent.test.ts
@@ -1,16 +1,8 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';
import { SERVER } from './utils';

describe('ItemIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Item in Generation 8 THEN returns data', async () => {
expect.assertions(2);

Expand Down
10 changes: 1 addition & 9 deletions __tests__/LaunchIntent.test.ts
@@ -1,16 +1,8 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';
import { SERVER } from './utils';

describe('LaunchIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Request to Launch THEN returns launch blurb', async () => {
expect.assertions(2);

Expand Down
10 changes: 1 addition & 9 deletions __tests__/MoveIntent.test.ts
@@ -1,16 +1,8 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';
import { SERVER } from './utils';

describe('MoveIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Normal move THEN returns regular data', async () => {
expect.assertions(2);

Expand Down
11 changes: 11 additions & 0 deletions __tests__/jest.setup.ts
@@ -0,0 +1,11 @@
import { setup, teardown } from './utils';

jest.retryTimes(2);

beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});
4 changes: 3 additions & 1 deletion jest.config.js
Expand Up @@ -2,5 +2,7 @@ module.exports = {
displayName: 'ts-jest',
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/__tests__/*.test.ts']
testMatch: ['<rootDir>/__tests__/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/__tests__/jest.setup.ts'],
testRunner: 'jest-circus/runner'
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"fs-nextra": "^0.4.7",
"husky": "^3.1.0",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"pretty-quick": "^2.0.1",
Expand Down

0 comments on commit 73ef48b

Please sign in to comment.