diff --git a/.eslintrc.json b/.eslintrc.json index c35d6b3b..b32e73b5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,11 +15,17 @@ }, "extends": ["eslint:recommended", "prettier"], "rules": { - "no-unused-vars": ["warn", { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - }] + "no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "caughtErrorsIgnorePattern": "^_" + } + ] + }, + "parserOptions": { + "sourceType": "module" }, "overrides": [ { diff --git a/apps/pokeapi-proxy/api/pokemon/pokemon.handlers.mjs b/apps/pokeapi-proxy/api/pokemon/pokemon.handlers.mjs index 4903cd37..9ee79304 100644 --- a/apps/pokeapi-proxy/api/pokemon/pokemon.handlers.mjs +++ b/apps/pokeapi-proxy/api/pokemon/pokemon.handlers.mjs @@ -12,7 +12,7 @@ export const getPokemonEndpointResources = async (req, res, next) => { 'Fetching all resources for the Pokémon endpoint from PokéAPI' ); const host = req.get('host'); - const protocol = host.match(/localhost\:\d+/) ? 'http' : 'https'; + const protocol = host.match(/localhost:\d+/) ? 'http' : 'https'; const { data } = await axios.get( `https://pokeapi.co/api/v2/pokemon/?limit=9000` ); diff --git a/test/pokeapi-proxy.test.js b/test/pokeapi-proxy.test.js new file mode 100644 index 00000000..e55e9a1b --- /dev/null +++ b/test/pokeapi-proxy.test.js @@ -0,0 +1,64 @@ +/* eslint-disable no-undef */ +const portMap = require('../port-map.json'); +const pokeapiProxyPort = portMap['pokeapi-proxy']; +const { baseUrl } = require('./jest-utils.js'); + +const BASE_URL = baseUrl(pokeapiProxyPort); + +describe('Pokémon api', () => { + it('Should return at minimum the first 151 Pokemon', async function () { + const response = await fetch(new URL('/api/pokemon', BASE_URL)); + const pokedex = await response.json(); + expect(response.status).toBe(200); + expect(pokedex.results.length).toBeGreaterThanOrEqual(151); + expect(pokedex.count).toBeGreaterThanOrEqual(151); + }); + + it('Should return Pikachu by name', async function () { + const response = await fetch(new URL('/api/pokemon/pikachu', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('pikachu'); + expect(pokemon.id).toBe(25); + }); + + it('Should return Pikachu by id', async function () { + const response = await fetch(new URL('/api/pokemon/25', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('pikachu'); + expect(pokemon.id).toBe(25); + }); + + it('Should return the female Nidoran by name', async function () { + const response = await fetch(new URL('/api/pokemon/nidoran-f', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('nidoran-f'); + expect(pokemon.id).toBe(29); + }); + + it('Should return the female Nidoran by id', async function () { + const response = await fetch(new URL('/api/pokemon/29', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('nidoran-f'); + expect(pokemon.id).toBe(29); + }); + + it('Should return Mr. Mime by name', async function () { + const response = await fetch(new URL('/api/pokemon/mr-mime', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('mr-mime'); + expect(pokemon.id).toBe(122); + }); + + it('Should return Mr. Mime by id', async function () { + const response = await fetch(new URL('/api/pokemon/122', BASE_URL)); + const pokemon = await response.json(); + expect(response.status).toBe(200); + expect(pokemon.name).toBe('mr-mime'); + expect(pokemon.id).toBe(122); + }); +}); diff --git a/test/ports.test.js b/test/ports.test.js index 146316a9..4580e139 100644 --- a/test/ports.test.js +++ b/test/ports.test.js @@ -1,4 +1,3 @@ -// TODO: Remove eslint-disable-next-line no-undef the minute expect can be labelled as defined const { readdirSync } = require('fs'); const { join } = require('path'); const portMap = require('../port-map.json');