diff --git a/__tests__/AbilityIntent.test.ts b/__tests__/AbilityIntent.test.ts
index b29ab97..e0de9bd 100755
--- a/__tests__/AbilityIntent.test.ts
+++ b/__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);
diff --git a/__tests__/DexIntent.test.ts b/__tests__/DexIntent.test.ts
index b1f8286..58035e6 100644
--- a/__tests__/DexIntent.test.ts
+++ b/__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);
@@ -38,7 +30,7 @@ describe('DexIntent', () => {
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.
`);
@@ -70,14 +62,14 @@ describe('DexIntent', () => {
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).
+ 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.
`);
@@ -110,8 +102,8 @@ describe('DexIntent', () => {
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.
`);
@@ -144,7 +136,7 @@ describe('DexIntent', () => {
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.
`);
@@ -209,15 +201,15 @@ describe('DexIntent', () => {
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.
`);
});
- 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)
@@ -230,7 +222,7 @@ describe('DexIntent', () => {
slots: {
POKEMON: {
name: 'POKEMON',
- value: 'aklsjdkjlashgdjlhaksgdjaghsdghasjd'
+ value: 'gigantamax charizard'
}
}
}
@@ -241,9 +233,141 @@ describe('DexIntent', () => {
expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
- 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.
- `);
+ 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.
+ `);
+ });
+
+ 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`
+ 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.
+ `);
+ });
+
+ 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`
+ 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.
+ `);
+ });
+
+ 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`
+ 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.
+ `);
+ });
+
+ 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`
+ 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.
+ `);
});
});
diff --git a/__tests__/ErrorHandling.test.ts b/__tests__/ErrorHandling.test.ts
new file mode 100755
index 0000000..74a425f
--- /dev/null
+++ b/__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`
+ 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.
+ `);
+ });
+});
diff --git a/__tests__/ItemIntent.test.ts b/__tests__/ItemIntent.test.ts
index e6b5613..aaa2798 100755
--- a/__tests__/ItemIntent.test.ts
+++ b/__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);
diff --git a/__tests__/LaunchIntent.test.ts b/__tests__/LaunchIntent.test.ts
index d3bb383..184140f 100755
--- a/__tests__/LaunchIntent.test.ts
+++ b/__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);
diff --git a/__tests__/MoveIntent.test.ts b/__tests__/MoveIntent.test.ts
index 5e2f8a9..60b70e0 100644
--- a/__tests__/MoveIntent.test.ts
+++ b/__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);
diff --git a/__tests__/jest.setup.ts b/__tests__/jest.setup.ts
new file mode 100755
index 0000000..2ef265d
--- /dev/null
+++ b/__tests__/jest.setup.ts
@@ -0,0 +1,11 @@
+import { setup, teardown } from './utils';
+
+jest.retryTimes(2);
+
+beforeAll(() => {
+ setup();
+});
+
+afterAll(() => {
+ teardown();
+});
diff --git a/jest.config.js b/jest.config.js
index f18a3c1..9ab1313 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -2,5 +2,7 @@ module.exports = {
displayName: 'ts-jest',
preset: 'ts-jest',
testEnvironment: 'node',
- testMatch: ['/__tests__/*.test.ts']
+ testMatch: ['/__tests__/*.test.ts'],
+ setupFilesAfterEnv: ['/__tests__/jest.setup.ts'],
+ testRunner: 'jest-circus/runner'
};
diff --git a/package.json b/package.json
index 3a31c65..dd96943 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/constants.ts b/src/constants.ts
index 5417961..d47024a 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -1,4 +1,5 @@
import { Abilities, DexDetails, GenderEntry, Items, MoveEntry, Moves, Pokemon, Query } from '@favware/graphql-pokemon';
+import { toTitleCase } from '@klasa/utils';
const AbilityFragment = `
fragment ability on AbilityEntry {
@@ -106,14 +107,24 @@ ${MoveFragment}
export const parsePrevos = (data: DexDetails) => {
const prevos: string[] = [];
- const hasEvoByLevel = (evolutionMethod: string) => Number(evolutionMethod);
+ const hasEvoByLevel = (evolutionMethod: string | null | undefined) => Number(evolutionMethod);
data.preevolutions!.forEach(pr => {
- prevos.push(`${pr.species} ${hasEvoByLevel ? `(Level: ${data.evolutionLevel})` : `(Special Condition: ${data.evolutionLevel})`}`);
+ prevos.push(
+ [
+ `${toTitleCase(pr.species)}`,
+ `${hasEvoByLevel(data.evolutionLevel) ? `(Level: ${data.evolutionLevel})` : `(Special Condition: ${data.evolutionLevel})`}`
+ ].join(' ')
+ );
if (pr.preevolutions) {
pr.preevolutions.forEach(prr => {
- prevos.push(`${prr.species} ${hasEvoByLevel ? `(Level: ${pr.evolutionLevel})` : `(Special Condition: ${pr.evolutionLevel})`}`);
+ prevos.push(
+ [
+ `${toTitleCase(prr.species)}`,
+ `${hasEvoByLevel(pr.evolutionLevel) ? `(Level: ${pr.evolutionLevel})` : `(Special Condition: ${pr.evolutionLevel})`}`
+ ].join(' ')
+ );
});
}
});
@@ -128,7 +139,7 @@ export const parseEvos = (data: DexDetails) => {
data.evolutions!.forEach(evo => {
evos.push(
[
- `${evo.species}`,
+ `${toTitleCase(evo.species)}`,
`${hasEvoByLevel(evo.evolutionLevel) ? `(Level: ${evo.evolutionLevel})` : `(Special Condition: ${evo.evolutionLevel})`}`
].join(' ')
);
@@ -137,7 +148,7 @@ export const parseEvos = (data: DexDetails) => {
evo.evolutions.forEach(evvo => {
evos.push(
[
- `${evvo.species}`,
+ `${toTitleCase(evvo.species)}`,
`${hasEvoByLevel(evvo.evolutionLevel) ? `(Level: ${evvo.evolutionLevel})` : `(Special Condition: ${evvo.evolutionLevel})`}`
].join(' ')
);
diff --git a/yarn.lock b/yarn.lock
index c1c5b84..f42fd1f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2565,6 +2565,28 @@ jest-changed-files@^24.9.0:
execa "^1.0.0"
throat "^4.0.0"
+jest-circus@^24.9.0:
+ version "24.9.0"
+ resolved "https://registry.yarnpkg.com/jest-circus/-/jest-circus-24.9.0.tgz#8a557683636807d537507eac02ba64c95b686485"
+ integrity sha512-dwkvwFtRc9Anmk1XTc+bonVL8rVMZ3CeGMoFWmv1oaQThdAgvfI9bwaFlZp+gLVphNVz6ZLfCWo3ERhS5CeVvA==
+ dependencies:
+ "@babel/traverse" "^7.1.0"
+ "@jest/environment" "^24.9.0"
+ "@jest/test-result" "^24.9.0"
+ "@jest/types" "^24.9.0"
+ chalk "^2.0.1"
+ co "^4.6.0"
+ expect "^24.9.0"
+ is-generator-fn "^2.0.0"
+ jest-each "^24.9.0"
+ jest-matcher-utils "^24.9.0"
+ jest-message-util "^24.9.0"
+ jest-snapshot "^24.9.0"
+ jest-util "^24.9.0"
+ pretty-format "^24.9.0"
+ stack-utils "^1.0.1"
+ throat "^4.0.0"
+
jest-cli@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-24.9.0.tgz#ad2de62d07472d419c6abc301fc432b98b10d2af"