Merge v2-beta changes into branch v2.0.0

This commit is contained in:
Tee
2021-03-23 21:36:22 -04:00
4 changed files with 26 additions and 13 deletions

View File

@ -3,5 +3,5 @@ module.exports = {
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testTimeout": 30000
"testTimeout": 300000
}

View File

@ -1,6 +1,6 @@
{
"name": "pokemon-tcg-sdk-typescript",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "Typescript SDK for the PokemonTCG API (https://pokemontcg.io)",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@ -6,6 +6,25 @@ import { Subtype } from '../enums/subtype';
import { Rarity } from '../enums/rarity';
import { Client } from '../client';
async function paginateAllCards(pageNumber: number, params?: Parameter): Promise<Card[]> {
let currentPage = pageNumber;
const client: Client = Client.getInstance();
const response: Card[] = await client.get<Card[]>('cards', { pageSize: 250, page: currentPage, ...params });
if (response.length === 0) {
return response;
} else {
currentPage++;
return response.concat(await paginateAllCards(currentPage));
}
}
export async function getAllCards(params?: Parameter): Promise<Card[]> {
const startingPage = 1;
const response: Card[] = await paginateAllCards(startingPage, params);
return response;
}
export async function findCardByID(id: string): Promise<Card> {
const client: Client = Client.getInstance();
const response: Card = await client.get<Card>('cards', id);
@ -18,13 +37,6 @@ export async function findCardsByQueries(params: Parameter): Promise<Card[]> {
return response;
}
export async function getAllCards(): Promise<Card[]> {
const params: Parameter = { pageSize: 250 };
const client: Client = Client.getInstance();
const response: Card[] = await client.get<Card[]>('cards', params);
return response;
}
export async function getTypes(): Promise<Type[]> {
const client: Client = Client.getInstance();

View File

@ -1,4 +1,4 @@
import { findCardByID, findCardsByQueries, getAllCards, getSupertypes, getSubtypes, getTypes, getRarities } from "../src/services/cardService";
import { findCardByID, findCardsByQueries, getSupertypes, getSubtypes, getTypes, getRarities } from "../src/services/cardService";
import { Parameter } from "../src/interfaces/parameter";
import { Card } from "../src/interfaces/card";
import { Type } from '../src/enums/type';
@ -19,9 +19,10 @@ describe('Card Service', () => {
expect(result.name).toEqual('Gardevoir');
})
it('should get a default list of cards using the cards resource with no query params', async () => {
const results: Card[] = await getAllCards();
expect(results).toHaveLength(250);
it('should get a maximum of 250 cards given a page number by default', async () => {
const totalCards = 250
const results: Card[] = await findCardsByQueries({ page: 1});
expect(results).toHaveLength(totalCards);
});
it('should get a list of card supertypes', async () => {