111 Commits

Author SHA1 Message Date
Tee
bf7c9b0c10 Update beta versioning 2021-03-24 20:08:47 -04:00
Tee
520a2116c3 Export remaining v2 interfaces 2021-03-24 20:08:00 -04:00
Tee
41617881fc Merge v2-beta changes into branch v2.0.0 2021-03-23 21:36:22 -04:00
Tee
e681d3a8db Resolve TypeScript card test warnings 2021-03-23 21:28:19 -04:00
Tee
4cb8376cd1 Test default max for card retrieval 2021-03-23 21:26:22 -04:00
Tee
59cba1b831 Update recursive pagination helper 2021-03-23 21:26:03 -04:00
Tee
2e34be017f Update beta version 2021-03-23 20:37:05 -04:00
Tee
1921973712 Test recursive pagination with total card length 2021-03-23 20:35:20 -04:00
Tee
a2b3fc3333 Recursively paginate all cards with getAllCards helper 2021-03-23 20:27:32 -04:00
Tee
aa0ca788ff Update testTimeout property in jest.config.js 2021-03-23 20:26:45 -04:00
Tee
648ebe40b4 Include beta tag in v2 number 2021-03-23 17:47:18 -04:00
Tee
dfead83c2e Update package version in package lock 2021-03-23 00:11:49 -04:00
Tee
04a1f912d3 Update git workflow to test dev 2021-03-20 23:45:01 -04:00
Tee
8304485af8 Add rapid strike and single strike subtype enums 2021-03-20 23:44:20 -04:00
Tee
dbfe4c4c99 Fix function name change title markdown 2021-03-20 23:35:14 -04:00
Tee
7b4520e557 Link migration guide to README 2021-03-20 23:32:11 -04:00
Tee
2499e665c7 Add proper steps to migrate 2021-03-20 23:31:55 -04:00
Tee
91d579261d Add migration guide draft 2021-03-20 23:25:40 -04:00
Tee
9713eaa497 docs: correct Set usage example 2021-03-19 00:33:19 -04:00
Tee
8dec64ce20 docs: Edit README title and PR step 2021-03-18 23:58:49 -04:00
Tee
f3778623c6 workflow: Add lint workflow 2021-03-18 23:48:02 -04:00
Tee
32e9bfb578 docs: Update README docs 2021-03-18 23:47:48 -04:00
Tee
0927395f0f chore(scripts): Update doc scripts. 2021-03-18 23:46:47 -04:00
Tee
c46b721652 Refactor query imports and types 2021-03-18 09:28:39 -04:00
Tee
5c67dcf4bf Use stringified parameter object for client 2021-03-18 09:27:47 -04:00
Tee
8293febb19 Export parameter interface 2021-03-18 09:24:12 -04:00
Tee
88010e4c74 Add parameter interface 2021-03-18 09:24:03 -04:00
Tee
4cec0fb24a Delete parameter enum 2021-03-18 09:23:15 -04:00
Tee
c9a4490e82 Delete query enum 2021-03-18 09:23:04 -04:00
Tee
08be3f8fff Add basic intro and card method examples 2021-03-17 23:52:35 -04:00
Tee
6ab4da3cbf Rename action name 2021-03-17 23:51:13 -04:00
349342db11 Merge pull request #3 from acupoftee/v2-migration
V2 migration
2021-03-16 00:25:53 -04:00
Tee
fd3df49bc8 Add name for contribution 2021-03-16 00:18:09 -04:00
Tee
9443263499 Update sdk version 2021-03-16 00:17:37 -04:00
Tee
aed5a32a3e Remove lint step 2021-03-16 00:15:55 -04:00
Tee
7ebfb80cb1 Add github workflows 2021-03-16 00:10:15 -04:00
Tee
0ef85368c8 Updated gitignore with .idea directory 2021-03-15 23:23:40 -04:00
Tee
5755c744a3 Add formatted and linted files 2021-03-15 23:23:06 -04:00
Tee
de16add8d1 Add eslint dependencies 2021-03-15 21:45:12 -04:00
Tee
315f8cbef3 Add prettierignore 2021-03-15 21:44:36 -04:00
Tee
8a3b2a0b7a Add eslint config files 2021-03-15 21:43:43 -04:00
Tee
66965487a7 Add return type to Client.getInstance 2021-03-15 12:35:47 -04:00
Tee
523201535d Add prettierrc.json 2021-03-15 08:45:16 -04:00
Tee
904c92bb9b Remove optional parameter in params to query function 2021-03-15 08:44:57 -04:00
Tee
0e4698f2a1 Install prettier dependency 2021-03-15 08:38:23 -04:00
Tee
417cced318 Add test timeout in jest config 2021-03-15 08:37:56 -04:00
Tee
b0a744fd58 Fix cardService test formatting 2021-03-14 21:36:53 -04:00
Tee
1033ad9dc2 Add tests for card enums 2021-03-14 21:33:46 -04:00
Tee
1bcdd1d990 Add param check 2021-03-14 21:33:20 -04:00
Tee
619ec93332 Fix spelling errors in card enums 2021-03-14 21:32:56 -04:00
Tee
517ee0ff53 Add functions for card constants 2021-03-14 21:32:36 -04:00
Tee
6f1c4958b1 Add enum types for select Card properties 2021-03-14 17:15:48 -04:00
Tee
eb01211d09 Use singular naming scheme for enums 2021-03-14 17:04:42 -04:00
Tee
bfc4ad92b9 Add search parameter enums 2021-03-12 22:01:41 -05:00
Tee
71266cf726 Update legality enum casing 2021-03-12 22:00:35 -05:00
Tee
11c0c9041f Add type enums 2021-03-12 21:58:57 -05:00
Tee
decba63848 Add supertype enums 2021-03-12 21:58:53 -05:00
Tee
da9f106165 Add subtype enums 2021-03-12 21:58:46 -05:00
Tee
6c034d399f Add rarity enums 2021-03-12 21:58:40 -05:00
Tee
de37e0ef40 Match Set property ordering with API resource ordering 2021-03-12 21:31:46 -05:00
Tee
4e87f38bc5 Match Card property order with API resource order 2021-03-12 21:31:36 -05:00
Tee
1492b96a23 Update testing dependencies 2021-03-11 19:40:07 -05:00
Tee
5435e233e9 Delete client.test.ts 2021-03-11 19:29:58 -05:00
Tee
32e6de135e Add Set Service test 2021-03-11 19:27:04 -05:00
Tee
735d428dc2 Export individual functions in setService 2021-03-11 19:26:23 -05:00
Tee
ed16e6e937 Remove query builder abstraction 2021-03-11 12:46:02 -05:00
Tee
33116796dd Export individual card service functions 2021-03-11 08:02:32 -05:00
Tee
1ab1add58a Add ampersand and parameter conditions in client.ts 2021-03-11 07:59:21 -05:00
Tee
8c75754623 Add passing card service integration tests 2021-03-11 07:57:39 -05:00
Tee
d9fcb2ed55 Merge typing updates from v2-migration branch 2021-03-10 09:00:23 -05:00
Tee
f86810201d Merge branch 'master' into v2-migration 2021-03-10 08:55:31 -05:00
Tee
bfa0502a1e Update and pin Axios to latest release 2021-03-09 20:06:10 -05:00
fcbf7849ff Merge pull request #2 from PokemonTCG/master
Update TypeScript
2021-03-09 17:58:46 -05:00
c00754f7df Merge pull request #18 from acupoftee/typescript-update
Update TypeScript to latest stable version
2021-03-05 13:54:00 -06:00
Tee
daf61a0f9c Upgrade TypeScript to latest stable release 2021-03-04 23:34:01 -05:00
Tee
ba2ce6e79b Use optional property syntax for ILegality 2021-03-04 07:45:38 -05:00
Tee
f47353849a Use new singleton instance of Client 2021-03-04 00:08:46 -05:00
Tee
9992fc99eb Remove coverage directory 2021-03-04 00:07:36 -05:00
Tee
54c42b7654 Update test directory in exclude setting 2021-03-04 00:07:18 -05:00
Tee
b6d387e7a5 Move test files to test directory 2021-03-04 00:06:52 -05:00
Tee
2bf257de45 Create jest config 2021-03-04 00:05:58 -05:00
Tee
4238438adb Use optional property syntax in TCGPlayer interface 2021-03-01 22:01:47 -05:00
Tee
0d00d4f984 Refactor Resistance and Weakness imports 2021-03-01 22:01:24 -05:00
Tee
979a6367b8 Refactor SDK imports 2021-03-01 22:01:12 -05:00
Tee
b12e306c73 Remove API service interface 2021-03-01 22:00:14 -05:00
Tee
320d62dd41 Extend shared stats interface to weakness and resistance 2021-03-01 21:31:52 -05:00
Tee
e7d36cc5a1 Use default exports for Set service methods instead of classes 2021-02-28 23:45:36 -05:00
Tee
fb33ea3617 Use default exports for service methods instead of classes 2021-02-28 23:44:13 -05:00
Tee
aa4179d523 Remove card and set classes 2021-02-28 22:55:20 -05:00
Tee
7f71588138 Use private client methods in services 2021-02-28 22:27:48 -05:00
Tee
537a236b42 Create private singleton class for Client 2021-02-27 23:06:15 -05:00
Tee
e588d35dd9 Remove QueryBuilder 2021-02-26 21:24:51 -05:00
Tee
5f19f8227e Add SetService 2021-02-26 19:56:41 -05:00
Tee
a7afa92184 Use generic APIService implemention for CardService 2021-02-26 10:58:05 -05:00
Tee
2f186599dd Refactor APIService into generic interface 2021-02-26 10:56:55 -05:00
Tee
f30b2313fe Remove QueryBuilder abstraction from CardService 2021-02-26 08:57:15 -05:00
Tee
4006272f4d Refactor newly merged interface names 2021-02-25 22:19:25 -05:00
Tee
43c1987a83 Refactor card interface names from merge 2021-02-25 22:11:17 -05:00
Tee
e8201df35f Transfer API information to client for ownership 2021-02-25 22:09:07 -05:00
Tee
363bcfd321 Refactor query interface imports 2021-02-25 22:08:38 -05:00
Tee
657605eaa0 Add API service interface 2021-02-25 22:08:02 -05:00
Tee
669e6db54c Refactor interface names 2021-02-25 22:02:32 -05:00
Tee
ade8606e8f Merge initial v2 changes 2021-02-25 20:47:55 -05:00
424a32af9c Merge pull request #1 from PokemonTCG/master
Add Initial v2 Data Structure Changes
2021-02-25 20:32:39 -05:00
9d5905a33f Merge pull request #16 from CptSpaceToaster/master
Initial update to v2
2021-02-22 16:15:34 -06:00
74055255e3 Fix tests 2021-02-22 12:05:08 -05:00
239b18bcd3 Initial update to v2 data structures 2021-02-22 12:05:03 -05:00
Tee
cec9ea8c5e Move API constants to client.ts for ownership 2021-02-19 19:29:44 -05:00
Tee
9b6acd5b9a Remove API constants from sdk.ts 2021-02-19 19:29:16 -05:00
25e1972242 1.2.6 2020-11-17 08:12:22 -06:00
668c6740e7 Moved tests and updated Set 2020-11-17 08:12:12 -06:00
41 changed files with 6172 additions and 2402 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

19
.eslintrc.json Normal file
View File

@ -0,0 +1,19 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-empty-function": 0,
"no-console": 1
}
}

36
.github/workflows/sdk_test.yaml vendored Normal file
View File

@ -0,0 +1,36 @@
name: Build
on:
pull_request:
push:
branches:
- master
- dev
jobs:
test:
name: Pokemon TCG TypeScript Integration Tests
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v1
- name: 'Setup Node'
uses: actions/setup-node@v1
with:
node-version: 12
- name: 'Install dependencies'
run: 'npm ci'
- name: 'Format SDK'
run: 'npm run prettier'
- name: 'Lint SDK'
run: 'npm run lint'
- name: 'Test SDK'
run: 'npm run test'
- name: 'Build SDK'
run: 'npm run build'

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
dist
*.tgz
.idea

2
.prettierignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

6
.prettierrc.json Normal file
View File

@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}

157
MIGRATING.md Normal file
View File

@ -0,0 +1,157 @@
# Migrating from v1 to v2
The functions and typings in V2 the SDK have been re-named to improve developer experience.
The guide will provide you with the steps to help you migrate your application.
## Type Changes
Interfaces are no longer prefixed with the letter `I`. **Interfaces in the TypeScript compile are used solely for type-checking purposes.**
Originally, `ICard` and `ISet` existed to be implemented with the `Card` and `Set` classes respectively. Because each function is now an independently exported function,
the TypeScript interfaces can be used as intended, which is to simply describe the shape of the data from the API:
`IQuery` was also changed to `Parameter` to complement the [new parameter syntax](https://docs.pokemontcg.io/#api_v2cards_list) in V2 of the API.
* `ICard` -> `Card`
* `ISet` -> `Set`
* `IAbility` -> `Ability`
* `IResistance` -> `Resistance`
* `IWeakness` -> `Weakness`
* `IAttack` -> `Attack`
* `IQuery` -> `Parameter`
## Function Changes
The API functions are no longer abstracted in classes. Instead, each function is an individual export which still returns
data of type `Card` or `Set` to reduce redundancy in the SDK. The function names were renamed to reveal intent as clearly as possible. This results
in code that is self documenting, and enforces a convention where the API functionality is described
thoroughly for developers.
There is no change in the function return types, nor underlying functionality. Functions will continue to return a generic promised based on the resource (i.e. `Promise<Card>`, `Promise<Set>`).
It is recommended to refactor the function names with the find-and-replace tool in your IDE or text editor in order for your project
to be compatible with V2 of the SDK.
## Card Functions
### `PokemonTCG.Card.all()` -> `PokemonTCG.getAllCards()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Card.all();
// V2
PokemonTCG.getAllCards();
```
### `PokemonTCG.Card.find()` -> `PokemonTCG.findCardByID()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Card.find('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
});
// V2
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
});
```
### `PokemonTCG.Card.where()` -> `PokemonTCG.findCardsByQueries()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value: 'Gardevoir' }];
PokemonTCG.Card.where(paramsV1).then((cards: PokemonTCG.Card[]) => {
console.log(card[0].name) // Gardevoir
});
// V2
const paramsV2: PokemonTCG.Parameter[] = { q: 'id:xy7-54' };
PokemonTCG.findCardsByQueries(paramsV2).then((cards: PokemonTCG.Card[]) => {
console.log(card[0].name) // Gardevoir
});
```
## Set Functions
### `PokemonTCG.Set.all()` -> `PokemonTCG.getAllSets()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Set.all();
// V2
PokemonTCG.getAllSets();
```
### `PokemonTCG.Set.find()` -> `PokemonTCG.findSetByID()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Set.find('base1').then((set: PokemonTCG.Set) => {
console.log(set.name) // Base
});
// V2
PokemonTCG.findSetByID('base1').then((set: PokemonTCG.Set) => {
console.log(set.name) // Base
});
```
### `PokemonTCG.Set.where()` -> `PokemonTCG.findSetsByQueries()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value:'Base' }];
PokemonTCG.Set.where(paramsV1).then((sets: PokemonTCG.Set[]) => {
console.log(sets[0].name) // Base
});
// V2
const paramsV2: PokemonTCG.Parameter[] = { q: 'name:Base' };
PokemonTCG.findSetsByQueries(paramsV2).then((sets: PokemonTCG.Set[]) => {
console.log(sets[0].name) // Base
});
```
## Meta Functions
### `PokemonTCG.Meta.allTypes()` -> `PokemonTCG.getTypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.getAllTypes();
// V2
PokemonTCG.getTypes();
```
### `PokemonTCG.Meta.allSupertypes()` -> `PokemonTCG.getSupertypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.allSupertypes();
// V2
PokemonTCG.getSupertypes();
```
### `PokemonTCG.Meta.allSubtypes()` -> `PokemonTCG.getSubtypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.allSubtypes();
// V2
PokemonTCG.getSubtypes();
```

233
README.md
View File

@ -1,156 +1,163 @@
# Pokemon TCG SDK TypeScript
# Pokémon TCG TypeScript SDK
This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io).
*Now supporting Version 2 of the Pokémon TCG API! Please refer to the [V1 to V2 Migration](https://docs.pokemontcg.io/#documentationmigration) section of the
official API docs for more information.*
***See the [migration guide](MIGRATING.md) for steps to update your app to use the latest supported version of the SDK***
[![pokemontcg-developers on discord](https://img.shields.io/badge/discord-pokemontcg--developers-738bd7.svg)](https://discord.gg/dpsTCvg)
![pokemon-tcg-sdk-typescript build status](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/actions/workflows/sdk_test.yaml/badge.svg
)
This is the TypeScript SDK for the [Pokémon Trading Card Game API](https://docs.pokemontcg.io).
## Installation
**npm**
npm install --save pokemon-tcg-sdk-typescript
npm install pokemon-tcg-sdk-typescript
**yarn**
yarn add pokemon-tcg-sdk-typescript
## Class Definitions
### Card
# Configuration
The SDK works out of the box! Simply import the SDK, and you're ready to go:
```typescript
ability: IAbility;
ancientTrait?: IAncientTrait;
artist: string;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
})
```
### IAbility
It is recommended to use an API key for version 2 of the API. By default, requests are limited to 20,000/day. Requests are rate limited to 1000 requests a day, and a maximum of 30 per minute.
To use the SDK with an API key, create an account at https://dev.pokemontcg.io to grab an API key.
Then set your API key to the environment variable `POKEMONTCG_API_KEY` in a `.env` file.
**Make sure to use this exact environment variable, otherwise the SDK will not be able to read the API key.**
# Usage
All function calls return generic promises like `Promise<T>` or `Promise<T[]>`
## Card Methods
* [findCardByID()](#findcardbyid)
* [findCardsByQueries()](#findcardbyqueries)
* [getAllCards()](#getallcards)
* [getTypes()](#gettypes)
* [getSupertypes()](#getsupertypes)
* [getSubtypes()](#getsubtypes)
* [getRarities()](#getrarities)
## Set Methods
* [findSetByID()](#findsetbyid)
* [findSetsByQueries()](#findsetbyqueries)
* [getAllSets()](#getallsets)
### findCardByID()
Returns a single Pokémon card given an ID.
```typescript
name: string;
text: string;
type: string;
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
});
```
### IAttack
### findCardByQueries()
Returns an array of cards filtered through a search query.
```typescript
cost: string[];
name: string;
text: string;
damage: string;
convertedEnergyCost: string;
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
const params: PokemonTCG.Query[] = { q: 'id:xy7-54' };
PokemonTCG.findCardsByQueries(params).then((cards: PokemonTCG.Card[]) => {
console.log(card[0].name) // Gardevoir
});
```
### getAllCards()
Returns all Pokémon cards available through recursive pagination.
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.getAllCards();
```
### IResistance, IWeakness
### getTypes()
Returns all Energy Types
```typescript
type: string;
value: string;
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.getTypes();
```
### Set
### getSupertypes()
Returns all Super Types
```typescript
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
updatedAt: string;
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.getSupertypes();
```
### IQuery
### getSubtypes()
Returns all Sub Types
```typescript
{ name: string, value: string | number }
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.getSubtypes();
```
## Method Definitions
### getRarities()
Returns all card Rarities
```typescript
Card.find(id: string): Promise<Card>
Card.where(params: IQuery[]): Promise<Card[]>
Card.all(): Promise<Card[]>
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
Set.find(id: string): Promise<Set>
Set.where(params: IQuery[]): Promise<Set[]>
Set.all(): Promise<Set[]>
PokemonTCG.getRarities();
```
### findSetByID()
Returns a single Pokémon card given an ID.
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
Meta.allTypes(): Promise<string[]>
Meta.allSubtypes(): Promise<string[]>
Meta.allSupertypes(): Promise<string[]>
PokemonTCG.findSetByID('base1').then((set: PokemonTCG.Set) => {
console.log(set.name) // Base
});
```
## Usage
All of the calls return generic promises like `Promise<T>` or `Promise<T[]>`. The type is determined from the class making the call. The examples here are using the `Card` class but the usage for the other classes are the same.
### findSetByQueries()
Returns an array of cards filtered through a search query.
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript'
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.Card.find('xy1')
.then(card => {
// do stuff with the card
})
.catch(error => {
// do something with the error
});
const params: PokemonTCG.Query[] = { q: 'name:Base' };
let params: PokemonTCG.IQuery[] = [{ name: 'name', value: 'Charizard' }];
PokemonTCG.Card.where(params)
.then(cards => {
// do stuff with the cards
})
.catch(error => {
// do something with the error
});
PokemonTCG.findSetsByQueries(params).then((sets: PokemonTCG.Set[]) => {
console.log(sets[0].name) // Base
});
```
### getAllSets()
Returns all Pokémon sets available through recursive pagination.
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
PokemonTCG.Card.all()
.then(cards => {
// do stuff with the cards
})
.catch(error => {
// do something with the error
});
PokemonTCG.getAllSets();
```
## Contributing
* Fork it (click the Fork button at the top of the page)
* Create your feature branch (git checkout -b my-new-feature)
* Make some changes and fix some bugs!
* Run the tests `npm run-script test`
* Test your changes in a project of yours:
* Create a link with [npm](https://docs.npmjs.com/cli/link.html) or [yarn](https://yarnpkg.com/lang/en/docs/cli/link/) (depending on what tool you installed this SDK with)
* In your project that **uses** the SDK, install the linked package with `yarn/npm link pokemon-tcg-sdk-typescript`
* Verify the SDK behaves as expected, and your changes took effect
* Commit your changes (git commit -am 'Add some feature')
* Push to the branch (git push origin my-new-feature)
* Create a new Pull Request
Contributions are welcome! If you want to contribute, feel free to fork the repository, open and issue, then submit a pull request.
ESLint and Prettier are used to enforce a consistent coding style.
### Setup
Raring to code your heart out? Awesome! Here's how to get started:
1. Open and issue with a bug or feature. Ensure the change is not already being worked on.
2. Fork and clone the repository from the `master` branch.
3. Create a feature branch.
4. Run `npm ci` to install exact versions specified in the `package-lock.json`.
5. Code your heart out!
6. Run `npm run test` to run ESLint and Jest tests.
7. (OPTIONAL) Test your changes in a project of yours:
1. Create a link with `npm` or `yarn` (depending on what tool you installed this SDK with)
2. In your project that uses the SDK, install the linked package with `yarn/npm link pokemon-tcg-sdk-typescript`
3. Verify the SDK behaves as expected, and your changes took effect
8. Submit a [pull request](https://github.com/PokemonTCG/pokemon-tcg-sdk-typescript/compare)! 🎉
## TODO
* Add more testing?

7
jest.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
"testRegex": '.*\\.test\\.ts$',
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testTimeout": 300000
}

7253
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "pokemon-tcg-sdk-typescript",
"version": "1.2.5",
"version": "2.1.0-beta.1",
"description": "Typescript SDK for the PokemonTCG API (https://pokemontcg.io)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@ -11,8 +11,11 @@
"SDK"
],
"scripts": {
"test": "mocha --reporter spec --require ts-node/register 'src/**/*.test.ts'",
"build": "tsc"
"prettier": "prettier --config .prettierrc.json 'src/**/*.ts' --write",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "npm run lint && jest",
"build": "npm run lint:fix && tsc"
},
"repository": {
"type": "git",
@ -22,18 +25,24 @@
"Bradyn Glines (https://github.com/glinesbdev)",
"CptSpaceToaster (https://github.com/CptSpaceToaster)",
"Monbrey (https://github.com/Monbrey)",
"Jonathan Meyer (https://github.com/jonathan-meyer)"
"Jonathan Meyer (https://github.com/jonathan-meyer)",
"Elisabeth Diang (https://github.com/acupoftee)"
],
"license": "MIT",
"dependencies": {
"axios": "^0.19.0",
"typescript": "^2.6.2"
"axios": "0.21.1"
},
"devDependencies": {
"@types/chai": "^4.1.1",
"@types/mocha": "^2.2.46",
"chai": "^4.1.2",
"mocha": "^8.2.1",
"ts-node": "^4.1.0"
"@types/jest": "26.0.20",
"@typescript-eslint/eslint-plugin": "4.17.0",
"@typescript-eslint/parser": "4.17.0",
"eslint": "7.22.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "3.3.1",
"jest": "26.6.3",
"prettier": "2.2.1",
"ts-jest": "26.5.3",
"ts-node": "4.1.0",
"typescript": "4.1.5"
}
}

View File

@ -1,63 +0,0 @@
import { IAbility } from '../interfaces/ability';
import { IAncientTrait } from '../interfaces/ancientTrait';
import { IAttack } from '../interfaces/attack';
import { ICard } from '../interfaces/card';
import { IQuery } from '../interfaces/query';
import { IResistance } from '../interfaces/resistance';
import { IWeakness } from '../interfaces/weakness';
import { QueryBuilder } from '../queryBuilder';
export class Card implements ICard {
ability: IAbility;
artist: string;
ancientTrait?: IAncientTrait;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
resource(): string {
return 'cards';
}
static async find(id: string): Promise<Card> {
return QueryBuilder.find(this, id)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
static async all(): Promise<Card[]> {
return QueryBuilder.all(this)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
static async where(params: IQuery[]): Promise<Card[]> {
return QueryBuilder.where(this, params)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
}

View File

@ -1,15 +0,0 @@
import { Client } from '../client';
export class Meta {
static async allTypes(): Promise<string[]> {
return Client.get('types');
}
static async allSubtypes(): Promise<string[]> {
return Client.get('subtypes');
}
static async allSupertypes(): Promise<string[]> {
return Client.get('supertypes');
}
}

View File

@ -1,45 +0,0 @@
import { ISet } from '../interfaces/set';
import { IQuery } from '../interfaces/query';
import { QueryBuilder } from '../queryBuilder';
export class Set implements ISet {
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
updatedAt: string;
resource(): string {
return 'sets';
}
static async find(id: string): Promise<Set> {
return QueryBuilder.find(this, id)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
static async all(): Promise<Set[]> {
return QueryBuilder.all(this)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
static async where(params: IQuery[]): Promise<Set[]> {
return QueryBuilder.where(this, params)
.then(response => {
return response;
})
.catch(error => Promise.reject(error));
}
}

View File

@ -1,37 +1,64 @@
import * as axios from 'axios';
import { API_URL, API_VERSION } from './sdk';
import { IQuery } from './interfaces/query';
import { Parameter } from './interfaces/parameter';
export class Client {
static apiUrl: string = `${API_URL}/v${API_VERSION}`;
private readonly POKEMONTCG_API_BASE_URL: string =
'https://api.pokemontcg.io';
private readonly POKEMONTCG_API_VERSION: string = '2';
private readonly POKEMONTCG_API_URL: string = `${this.POKEMONTCG_API_BASE_URL}/v${this.POKEMONTCG_API_VERSION}`;
private readonly POKEMONTCG_API_KEY?: string =
process.env.POKEMONTCG_API_KEY;
static async get(resource: string, params?: IQuery[] | string): Promise<any> {
let url: string = `${this.apiUrl}/${resource}`;
const config: axios.AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json'
}
};
private static instance: Client;
if(typeof params === 'string') url += `/${params}`;
else url += `?${this.paramsToQuery(params)}`;
private constructor() {}
return axios.default.get<any>(url, config)
.then(response => {
return response.data[Object.keys(response.data)[0]];
})
.catch(error => Promise.reject(error));
}
public static getInstance(): Client {
if (!Client.instance) {
Client.instance = new Client();
}
private static paramsToQuery(params?: IQuery[]): string {
let query: string = '';
if (params) {
params.map((q: IQuery) => {
query += `${q.name}=${encodeURIComponent(q.value.toString())}`.concat('&');
});
return Client.instance;
}
return query;
}
}
async get<T>(resource: string, params?: Parameter | string): Promise<T> {
let url = `${this.POKEMONTCG_API_URL}/${resource}`;
const headers = {
'Content-Type': 'application/json',
};
if (this.POKEMONTCG_API_KEY) {
headers['X-Api-Key'] = this.POKEMONTCG_API_KEY;
}
const config: axios.AxiosRequestConfig = {
headers,
};
if (typeof params === 'string') {
url += `/${params}`;
} else if (params) {
url += `?${this.stringify(params)}`;
}
return axios.default
.get<T>(url, config)
.then((response) => {
return response.data[Object.keys(response.data)[0]];
})
.catch((error) => Promise.reject(error));
}
private stringify(params: Parameter): string {
const queryString = Object.keys(params)
.map(
(key: string) =>
`${encodeURIComponent(key)}=${encodeURIComponent(
params[key]
)}`
)
.join('&');
return queryString;
}
}

View File

@ -1,86 +0,0 @@
import * as chai from 'chai';
import { Client } from '../client';
import { IQuery } from '../interfaces/query';
const expect = chai.expect;
describe('Client', () => {
it('should get a single using the cards resource and query params' , () => {
const params: IQuery[] = [{
name: 'id',
value: 'xy7-54'
}];
Client.get('cards', params)
.then(response => {
expect(response).to.be.a('array');
expect(response[0].name).to.equal('Gardevoir');
});
});
it('should get a default list of cards using the cards resource with no query params', () => {
Client.get('cards')
.then(response => {
expect(response).to.be.a('array');
expect(response.length).to.equal(100);
});
});
it('should get sets using the sets resource and query params', () => {
const params: IQuery[] = [{
name: 'name',
value: 'Base'
}];
Client.get('sets', params)
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('object');
});
});
it('should get a single set using the sets resource and query params', () => {
const params: IQuery[] = [{
name: 'id',
value: 'base1'
}];
Client.get('sets', params)
.then(response => {
expect(response).to.be.a('array');
expect(response[0].name).to.equal('Base');
});
});
it('should get a default list of sets using the sets resource with no query params', () => {
Client.get('sets')
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('object');
expect(response[0].code).to.equal('base1');
});
});
it('should get a list of types using the types resource', () => {
Client.get('types')
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('string');
});
});
it('should get a list of supertypes using the supertypes resource', () => {
Client.get('supertypes')
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('string');
});
});
it('should get a list of subtypes using the subtypes resource', () => {
Client.get('subtypes')
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('string');
});
});
});

View File

@ -1,43 +0,0 @@
import * as chai from 'chai';
import { Card } from '../classes/card';
import { QueryBuilder } from '../queryBuilder';
import { IQuery } from '../interfaces/query';
const expect = chai.expect;
describe('QueryBuilder', () => {
it('should use find to get a single instance', () => {
QueryBuilder.find<Card>(Card, 'xy7-54')
.then(card => {
expect(card).to.be.a('object');
expect(card.name).to.equal('Gardevoir');
});
});
it('should use where to filter data', () => {
const params: IQuery[] = [
{
name: 'name',
value: 'Charizard'
},
{
name: 'setCode',
value: 'base1'
}
];
QueryBuilder.where<Card>(Card, params)
.then(cards => {
expect(cards.length).to.equal(1);
expect(cards[0].id).to.equal('base1-4');
expect(cards[0].set).to.equal('Base');
});
});
it('should use all to get all cards', () => {
QueryBuilder.all<Card>(Card)
.then(cards => {
expect(cards.length).to.equal(1000);
});
});
});

25
src/enums/rarity.ts Normal file
View File

@ -0,0 +1,25 @@
export enum Rarity {
AmazingRare = 'Amazing Rare',
Common = 'Common',
Legend = 'LEGEND',
Promo = 'Promo',
Rare = 'Rare',
RareAce = 'Rare ACE',
RareBreak = 'Rare BREAK',
RareHolo = 'Rare Holo',
RareHoloEX = 'Rare Holo EX',
RareHoloGX = 'Rare Holo GX',
RareHoloLVX = 'Rare Holo LV.X',
RareHoloStar = 'Rare Holo Star',
RareHoloV = 'Rare Holo V',
RareHoloVMAX = 'Rare Holo VMAX',
RarePrime = 'Rare Prime',
RarePrimeStar = 'Rare Prism Star',
RareRainbow = 'Rare Rainbow',
RareSecret = 'Rare Secret',
RareShining = 'Rare Shining',
RareShiny = 'Rare Shiny',
RareShinyGX = 'Rare Shiny GX',
RareUltra = 'Rare Ultra',
Uncommon = 'Uncommon',
}

27
src/enums/subtype.ts Normal file
View File

@ -0,0 +1,27 @@
export enum Subtype {
Break = 'BREAK',
Baby = 'Baby',
Basic = 'Basic',
EX = 'EX',
GX = 'GX',
GoldenrodGameCorner = 'Goldenrod Game Corner',
Item = 'Item',
Legend = 'LEGEND',
LevelUp = 'Level-Up',
Mega = 'MEGA',
PokemonTool = 'Pokémon Tool',
PokemonToolF = 'Pokémon Tool F',
Restored = 'Restored',
RocketsSecretMachine = "Rocket's Secret Machine",
Special = 'Special',
Stadium = 'Stadium',
StageOne = 'Stage 1',
StageTwo = 'Stage 2',
Supporter = 'Supporter',
TagTeam = 'TAG TEAM',
TechnicalMachine = 'Technical Machine',
V = 'V',
VMax = 'VMAX',
RapidStrike = 'Rapid Strike',
SingleStrike = 'Single Strike'
}

5
src/enums/supertype.ts Normal file
View File

@ -0,0 +1,5 @@
export enum Supertype {
Energy = 'Energy',
Pokemon = 'Pokémon',
Trainer = 'Trainer',
}

13
src/enums/type.ts Normal file
View File

@ -0,0 +1,13 @@
export enum Type {
Colorless = 'Colorless',
Darkness = 'Darkness',
Dragon = 'Dragon',
Fairy = 'Fairy',
Fighting = 'Fighting',
Fire = 'Fire',
Grass = 'Grass',
Lightening = 'Lightning',
Metal = 'Metal',
Psychic = 'Psychic',
Water = 'Water',
}

View File

@ -1,5 +1,5 @@
export interface IAbility {
name: string;
text: string;
type: string;
}
export interface Ability {
name: string;
text: string;
type: string;
}

View File

@ -1,4 +1,4 @@
export interface IAncientTrait {
name: string;
text: string;
}
export interface AncientTrait {
name: string;
text: string;
}

View File

@ -1,7 +1,7 @@
export interface IAttack {
convertedEnergyCost: string;
cost: string[];
damage: string;
name: string;
text: string;
}
export interface Attack {
convertedEnergyCost: number;
cost: string[];
damage: string;
name: string;
text: string;
}

View File

@ -1,32 +1,41 @@
import { IAbility } from '../interfaces/ability';
import { IAncientTrait } from './ancientTrait';
import { IAttack } from '../interfaces/attack';
import { IResistance } from '../interfaces/resistance';
import { IWeakness } from '../interfaces/weakness';
import { Ability } from './ability';
import { AncientTrait } from './ancientTrait';
import { Attack } from './attack';
import { Resistance, Weakness } from './stats';
import { CardImage } from './image';
import { ILegality } from './legality';
import { Set } from './set';
import { TCGPlayer } from './tcgplayer';
export interface ICard {
ability: IAbility;
ancientTrait?: IAncientTrait;
artist: string;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
}
import { Type } from '../enums/type';
import { Supertype } from '../enums/supertype';
import { Subtype } from '../enums/subtype';
import { Rarity } from '../enums/rarity';
export interface Card {
id: string;
name: string;
supertype: Supertype;
subtypes: Subtype[];
hp?: string;
types?: Type[];
evolesFrom?: string;
evolvesTo?: string[];
rules?: string[];
ancientTrait?: AncientTrait;
abilities?: Ability[];
attacks?: Attack[];
weaknesses?: Weakness[];
resistances?: Resistance[];
retreatCost?: string[];
convertedRetreatCost?: number;
set: Set;
number: string;
artist?: string;
rarity: Rarity;
flavorText?: string;
nationalPokedexNumbers?: number[];
legalities: ILegality;
images: CardImage;
tcgplayer?: TCGPlayer;
}

9
src/interfaces/image.ts Normal file
View File

@ -0,0 +1,9 @@
export interface SetImage {
symbol: string;
logo: string;
}
export interface CardImage {
small: string;
large: string;
}

View File

@ -0,0 +1,10 @@
export enum Legality {
Legal = 'Legal',
Banned = 'Banned',
}
export interface ILegality {
expanded?: Legality;
standard?: Legality;
unlimited?: Legality;
}

View File

@ -0,0 +1,6 @@
export interface Parameter {
q?: string;
orderBy?: string;
page?: number;
pageSize?: number;
}

View File

@ -1,4 +0,0 @@
export interface IQuery {
name: string;
value: string | number;
}

View File

@ -1,4 +0,0 @@
export interface IResistance {
type: string;
value: string;
}

View File

@ -1,14 +1,15 @@
export interface ISet {
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
updatedAt: string;
updatedSince: string;
}
import { SetImage } from './image';
import { ILegality } from './legality';
export interface Set {
id: string;
name: string;
series: string;
printedTotal: number;
total: number;
legalities: ILegality;
ptcgoCode: string;
releaseDate: string;
updatedAt: string;
images: SetImage;
}

8
src/interfaces/stats.ts Normal file
View File

@ -0,0 +1,8 @@
interface Stats {
type: string;
value: string;
}
export interface Resistance extends Stats {}
export interface Weakness extends Stats {}

View File

@ -0,0 +1,17 @@
export interface TCGPlayer {
url: string;
updatedAt: string;
prices: {
normal?: Price;
holofoil?: Price;
reverseHolofoil?: Price;
};
}
export interface Price {
low: number | null;
mid: number | null;
high: number | null;
market: number | null;
directLow: number | null;
}

View File

@ -1,4 +0,0 @@
export interface IWeakness {
type: string;
value: string;
}

View File

@ -1,28 +0,0 @@
import { Client } from './client';
import { Card } from './classes/card';
import { Set } from './classes/set';
import { IQuery } from './interfaces/query';
export class QueryBuilder {
static all<T extends Card | Set>(type: {new (): T}): Promise<T[]> {
const t = new type();
const params: IQuery[] = [{
name: 'pageSize',
value: 1000
}];
return Client.get(t.resource(), params);
}
static find<T extends Card | Set>(type: {new (): T}, id: string): Promise<T> {
const t = new type();
return Client.get(t.resource(), id);
}
static where<T extends Card | Set>(type: {new (): T}, params: IQuery[]): Promise<T[]> {
const t = new type();
return Client.get(t.resource(), params);
}
}

View File

@ -1,16 +1,20 @@
// Constants
export const API_URL: string = 'https://api.pokemontcg.io';
export const API_VERSION: string = '1';
// Classes
export * from './classes/card';
export * from './classes/set';
export * from './classes/meta';
// Interfaces
export * from './interfaces/ability';
export * from './interfaces/attack';
export * from './interfaces/card';
export * from './interfaces/query';
export * from './interfaces/resistance';
export * from './interfaces/weakness';
export * from './interfaces/parameter';
export * from './interfaces/stats';
export * from './interfaces/set';
export * from './interfaces/image';
export * from './interfaces/tcgplayer';
export * from './interfaces/legality';
// Enums
export * from './enums/type';
export * from './enums/supertype';
export * from './enums/subtype';
export * from './enums/rarity';
// Services
export * from './services/cardService';
export * from './services/setService';

View File

@ -0,0 +1,66 @@
import { Parameter } from '../interfaces/parameter';
import { Card } from '../interfaces/card';
import { Type } from '../enums/type';
import { Supertype } from '../enums/supertype';
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);
return response;
}
export async function findCardsByQueries(params: Parameter): Promise<Card[]> {
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();
const response: Type[] = await client.get<Type[]>('types');
return response;
}
export async function getSupertypes(): Promise<Supertype[]> {
const client: Client = Client.getInstance();
const response: Supertype[] = await client.get<Supertype[]>('supertypes');
return response;
}
export async function getSubtypes(): Promise<Subtype[]> {
const client: Client = Client.getInstance();
const response: Subtype[] = await client.get<Subtype[]>('subtypes');
return response;
}
export async function getRarities(): Promise<Rarity[]> {
const client: Client = Client.getInstance();
const response: Rarity[] = await client.get<Rarity[]>('rarities');
return response;
}

View File

@ -0,0 +1,23 @@
import { Parameter } from '../interfaces/parameter';
import { Set } from '../interfaces/set';
import { Client } from '../client';
export async function findSetByID(id: string): Promise<Set> {
const client: Client = Client.getInstance();
const response: Set = await client.get<Set>('sets', id);
return response;
}
export async function findSetsByQueries(params: Parameter): Promise<Set[]> {
const client: Client = Client.getInstance();
const response: Set[] = await client.get<Set[]>('sets', params);
return response;
}
export async function getAllSets(): Promise<Set[]> {
const params: Parameter = { pageSize: 250 };
const client: Client = Client.getInstance();
const response: Set[] = await client.get<Set[]>('sets', params);
return response;
}

55
test/cardService.test.ts Normal file
View File

@ -0,0 +1,55 @@
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';
import { Supertype } from '../src/enums/supertype';
import { Subtype } from '../src/enums/subtype';
import { Rarity } from '../src/enums/rarity';
describe('Card Service', () => {
it('should get a single card using query parameters', async () => {
const params: Parameter = { q: 'id:xy7-54' }
const result: Card[] = await findCardsByQueries(params);
expect(result[0].name).toEqual('Gardevoir');
})
it('should get a single card using a card id', async () => {
const result: Card = await findCardByID('xy7-54');
expect(result.name).toEqual('Gardevoir');
})
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 () => {
const expected: Supertype[] = Object.values(Supertype);
const result: Supertype[] = await getSupertypes();
expect(expected.sort()).toEqual(result.sort());
});
it('should get a list of card subtypes', async () => {
const expected: Subtype[] = Object.values(Subtype);
const result: Subtype[] = await getSubtypes();
expect(expected.sort()).toEqual(result.sort());
});
it('should get a list of card rarities', async () => {
const expected: Rarity[] = Object.values(Rarity);
const result: Rarity[] = await getRarities();
expect(expected.sort()).toEqual(result.sort());
});
it('should get a list of card types', async () => {
const expected: Type[] = Object.values(Type);
const result: Type[] = await getTypes();
expect(expected.sort()).toEqual(result.sort());
});
})

22
test/setService.test.ts Normal file
View File

@ -0,0 +1,22 @@
import { findSetByID, findSetsByQueries, getAllSets } from '../src/services/setService';
import { Parameter } from "../src/interfaces/parameter";
import { Set } from "../src/interfaces/set";
describe('Set Service', () => {
it('should get a single set using query parameters', async () => {
const params: Parameter = { q: 'name:Base' };
const result: Set[] = await findSetsByQueries(params);
expect(result[0].name).toEqual('Base');
})
it('should get a single set using a set id', async () => {
const result: Set = await findSetByID('base1');
expect(result.name).toEqual('Base');
})
it('should get a default list of sets using the sets resource with no query params', async () => {
const results: Set[] = await getAllSets();
expect(results.length).toBeLessThanOrEqual(250);
});
})

View File

@ -6,9 +6,13 @@
"outDir": "./dist",
"sourceMap": true,
"experimentalDecorators": true,
"lib": ["ES2015"]
"lib": ["ES6"]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"test"
]
}