Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pokeapi test #620

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion apps/pokeapi-proxy/api/pokemon/pokemon.handlers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
Expand Down
64 changes: 64 additions & 0 deletions test/pokeapi-proxy.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
1 change: 0 additions & 1 deletion test/ports.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
Loading