Merge pull request #3 from acupoftee/v2-migration

V2 migration
This commit is contained in:
Tee Diang
2021-03-16 00:25:53 -04:00
committed by GitHub
38 changed files with 5918 additions and 867 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
}
}

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
}

View File

@ -1,86 +0,0 @@
import * as chai from 'chai';
import { Client } from '../src/client';
import { IQuery } from '../src/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('Ampharos');
});
});
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(250);
});
});
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].id).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,38 +0,0 @@
import * as chai from 'chai';
import { Card } from '../src/classes/card';
import { QueryBuilder } from '../src/queryBuilder';
import { IQuery } from '../src/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: 'q',
value: 'name:Charizard set.id: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.name).to.equal('Base');
});
});
it('should use all to get all cards', () => {
QueryBuilder.all<Card>(Card)
.then(cards => {
expect(cards.length).to.equal(250);
});
});
});

7
jest.config.js Normal file
View File

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

5878
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.6",
"version": "2.0.0",
"description": "Typescript SDK for the PokemonTCG API (https://pokemontcg.io)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@ -11,7 +11,10 @@
"SDK"
],
"scripts": {
"test": "mocha --reporter spec --require ts-node/register 'coverage/**/*.test.ts'",
"format": "prettier --config .prettierrc.json 'src/**/*.ts' --write",
"lint": "eslint . --ext .ts",
"lint-and-fix": "eslint . --ext .ts --fix",
"test": "jest",
"build": "tsc"
},
"repository": {
@ -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.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,66 +0,0 @@
import { IAbility } from '../interfaces/ability';
import { IAncientTrait } from '../interfaces/ancientTrait';
import { IAttack } from '../interfaces/attack';
import { ICard } from '../interfaces/card';
import { ICardImage } from '../interfaces/image';
import { ILegality } from '../interfaces/legality';
import { IQuery } from '../interfaces/query';
import { IResistance } from '../interfaces/resistance';
import { ISet } from '../interfaces/set';
import { ITCGPlayer } from '../interfaces/tcgplayer';
import { IWeakness } from '../interfaces/weakness';
import { QueryBuilder } from '../queryBuilder';
export class Card implements ICard {
abilities: IAbility[];
artist: string;
ancientTrait?: IAncientTrait;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
images: ICardImage;
legalities: ILegality;
name: string;
nationalPokedexNumbers: number[];
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
rules: string[];
set: ISet;
subtypes: string[];
supertype: string;
tcgplayer: ITCGPlayer | undefined;
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,19 +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');
}
static allRarities(): Promise<string[]> {
return Client.get('rarities');
}
}

View File

@ -1,46 +0,0 @@
import { ISet } from '../interfaces/set';
import { IQuery } from '../interfaces/query';
import { QueryBuilder } from '../queryBuilder';
import { ILegality } from '../interfaces/legality';
import { ISetImage } from '../interfaces/image';
export class Set implements ISet {
id: string;
images: ISetImage;
legalities: ILegality;
name: string;
printedTotal: number;
ptcgoCode: string;
releaseDate: string;
series: string;
total: 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,71 @@
import * as axios from 'axios';
import { API_URL, API_VERSION } from './sdk';
import { IQuery } from './interfaces/query';
import { Query } from './interfaces/query';
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?: Query[] | 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') {
if (
params.toLowerCase().includes('page') ||
params.toLowerCase().includes('order')
)
url += `?${params}`;
else url += `/${params}`;
} else if (params) url += `?q=${this.paramsToQuery(params)}`;
return axios.default
.get<T>(url, config)
.then((response) => {
return response.data[Object.keys(response.data)[0]];
})
.catch((error) => Promise.reject(error));
}
private paramsToQuery(params: Query[]): string {
let query = '';
const paramsLength: number = params.length;
params.map((q: Query, i: number) => {
if (paramsLength === i + 1) {
query += `${q.name}:${encodeURIComponent(q.value.toString())}`;
} else {
query += `${q.name}:${encodeURIComponent(
q.value.toString()
)}`.concat('&');
}
});
return query;
}
}

6
src/enums/parameter.ts Normal file
View File

@ -0,0 +1,6 @@
export enum Parameter {
Query = 'q',
Page = 'page',
PageSize = 'pageSize',
Order = 'orderBy',
}

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',
}

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

@ -0,0 +1,25 @@
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',
}

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: number;
cost: string[];
damage: string;
name: string;
text: string;
}
export interface Attack {
convertedEnergyCost: number;
cost: string[];
damage: string;
name: string;
text: string;
}

View File

@ -1,36 +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 { ICardImage } from './image';
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 { ISet } from './set';
import { ITCGPlayer } from './tcgplayer';
import { Set } from './set';
import { TCGPlayer } from './tcgplayer';
export interface ICard {
abilities: IAbility[];
artist: string;
ancientTrait?: IAncientTrait;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
flavorText: string;
hp: string;
id: string;
images: ICardImage;
legalities: ILegality;
name: string;
nationalPokedexNumbers: number[];
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
rules: string[];
set: ISet;
subtypes: string[];
supertype: string;
tcgplayer: ITCGPlayer | undefined;
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;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +1,15 @@
import { ISetImage } from "./image";
import { ILegality } from "./legality";
import { SetImage } from './image';
import { ILegality } from './legality';
export interface ISet {
id: string;
images: ISetImage;
legalities: ILegality;
name: string;
printedTotal: number;
ptcgoCode: string;
releaseDate: string;
series: string;
total: number;
updatedAt: string;
}
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

@ -1,17 +1,17 @@
export interface ITCGPlayer {
url: string;
updatedAt: string;
prices: {
normal: IPrice | undefined;
holofoil: IPrice | undefined;
reverseHolofoil: IPrice | undefined;
}
export interface TCGPlayer {
url: string;
updatedAt: string;
prices: {
normal?: Price;
holofoil?: Price;
reverseHolofoil?: Price;
};
}
export interface IPrice {
low: number | null
mid: number | null
high: number | null
market: number | null
directLow: number | null
}
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: 250,
}];
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,17 @@
// Constants
export const API_URL: string = 'https://api.pokemontcg.io';
export const API_VERSION: string = '2';
// 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/stats';
// Enums
export * from './enums/type';
export * from './enums/supertype';
export * from './enums/subtype';
export * from './enums/rarity';
export * from './enums/parameter';
// Services
export * from './services/cardService';
export * from './services/setService';

View File

@ -0,0 +1,55 @@
import { Query } from '../interfaces/query';
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';
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: Query[]): Promise<Card[]> {
const client: Client = Client.getInstance();
const response: Card[] = await client.get<Card[]>('cards', params);
return response;
}
export async function getAllCards(): Promise<Card[]> {
const param = 'pageSize:250';
const client: Client = Client.getInstance();
const response: Card[] = await client.get<Card[]>('cards', param);
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 { Query } from '../interfaces/query';
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: Query[]): 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 param = 'pageSize:250';
const client: Client = Client.getInstance();
const response: Set[] = await client.get<Set[]>('sets', param);
return response;
}

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

@ -0,0 +1,57 @@
import { findCardByID, findCardsByQueries, getAllCards, getSupertypes, getSubtypes, getTypes, getRarities } from "../src/services/cardService";
import { Query } from "../src/interfaces/query";
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: Query[] = [{
name: 'id',
value: '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 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 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());
});
})

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

@ -0,0 +1,25 @@
import { findSetByID, findSetsByQueries, getAllSets } from '../src/services/setService';
import { Query } from "../src/interfaces/query";
import { Set } from "../src/interfaces/set";
describe('Set Service', () => {
it('should get a single set using query parameters', async () => {
const params: Query[] = [{
name: 'name',
value: '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

@ -13,6 +13,6 @@
],
"exclude": [
"node_modules",
"coverage"
"test"
]
}