Skip to content

Commit

Permalink
Merge 5f662f2 into 08e52b1
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrzy committed Oct 9, 2020
2 parents 08e52b1 + 5f662f2 commit 4d79787
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 78 deletions.
219 changes: 156 additions & 63 deletions __tests__/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,90 +24,183 @@ describe('bggXmlApiClient client', () => {
});

describe('bggXmlApiClient client wrappers', () => {
it('gets geeklist with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggGeeklist({ id: 272940, comments: 1 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).title).toEqual('#36,5 Polski MatHandel (Polish Math Trade)');
describe('getBggCollection', () => {
it('gets collection with given username', async () => {
jest.setTimeout(60000);
const { data } = await getBggCollection({ username: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(parseInt((data as any).totalitems, 10)).toBeGreaterThan(200);
});

it('gets collection with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggCollection({ username: 'Qrzy88', id: 173346 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(parseInt((data as any).totalitems, 10)).toEqual(1);
});

it('gets collection with list of IDs', async () => {
jest.setTimeout(60000);
const { data } = await getBggCollection({ username: 'Qrzy88', id: [173346, 202976] });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(parseInt((data as any).totalitems, 10)).toEqual(2);
});
});

it('gets collection with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggCollection({ username: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(parseInt((data as any).totalitems, 10)).toBeGreaterThan(200);
describe('getBggFamily', () => {
it('gets family with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggFamily({ id: 12210 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item.name.value).toEqual('Mechanism: 4X');
});

it('gets family with list of IDs', async () => {
jest.setTimeout(60000);
const { data } = await getBggFamily({ id: [12210, 17552] });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[0].name.value).toEqual('Mechanism: 4X');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[1].name.value).toEqual('Game: 7 Wonders');
});
});

it('gets family with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggFamily({ id: 12210 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item.name.value).toEqual('Mechanism: 4X');
describe('getBggForum', () => {
it('gets forum with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggForum({ id: 19 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).title).toEqual('General Gaming');
});
});

it('gets forum with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggForum({ id: 19 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).title).toEqual('General Gaming');
describe('getBggForumlist', () => {
it('gets forumlist with given ID', async () => {
jest.setTimeout(60000);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { data } = await getBggForumlist({ id: 13, type: 'thing' } as any);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).forum)).toBe(true);
});
});

it('gets forumlist with given ID', async () => {
jest.setTimeout(60000);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { data } = await getBggForumlist({ id: 13, type: 'thing' } as any);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).forum)).toBe(true);
describe('getBggGeeklist', () => {
it('gets geeklist with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggGeeklist({ id: 272940, comments: 1 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).title).toEqual('#36,5 Polski MatHandel (Polish Math Trade)');
});
});

it('gets guild with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggGuild({ id: 1497 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).name).toEqual('#boardgames');
describe('getBggGuild', () => {
it('gets guild with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggGuild({ id: 1497 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).name).toEqual('#boardgames');
});
});

it('gets hot', async () => {
jest.setTimeout(60000);
const { data } = await getBggHot({ type: 'boardgame' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
describe('getBggHot', () => {
it('gets hot', async () => {
jest.setTimeout(60000);
const { data } = await getBggHot({ type: 'boardgame' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
});
});

it('gets plays with given username', async () => {
jest.setTimeout(60000);
const { data } = await getBggPlays({ username: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).username).toEqual('Qrzy88');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).userid).toEqual('1381959');
describe('getBggPlays', () => {
it('gets plays with given username', async () => {
jest.setTimeout(60000);
const { data } = await getBggPlays({ username: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).username).toEqual('Qrzy88');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).userid).toEqual('1381959');
});

it('throws when necessary params are not given', async () => {
jest.setTimeout(60000);
expect(() => getBggPlays({})).toThrowError();
expect(() => getBggPlays({ type: 'thing' })).toThrowError();
expect(() => getBggPlays({ id: 1 })).toThrowError();
});
});

it('gets search with given term', async () => {
jest.setTimeout(60000);
const { data } = await getBggSearch({ query: 'alhambra' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
describe('getBggSearch', () => {
it('gets search with given term', async () => {
jest.setTimeout(60000);
const { data } = await getBggSearch({ query: 'alhambra' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
});

it('gets search with given term and type', async () => {
jest.setTimeout(60000);
const { data } = await getBggSearch({ query: 'alhambra', type: 'boardgame' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
});

it('gets search with given term and types list', async () => {
jest.setTimeout(60000);
const { data } = await getBggSearch({ query: 'alhambra', type: ['boardgame', 'boardgameexpansion'] });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Array.isArray((data as any).item)).toBe(true);
});
});

it('gets thing with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggThing({ id: 6249 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item.type).toEqual('boardgame');
describe('getBggThing', () => {
it('gets thing with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggThing({ id: 6249 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item.type).toEqual('boardgame');
});

it('gets thing with list of IDs', async () => {
jest.setTimeout(60000);
const { data } = await getBggThing({ id: [6249, 202976] });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[0].type).toEqual('boardgame');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[1].type).toEqual('boardgameexpansion');
});

it('gets thing with given ID and type', async () => {
jest.setTimeout(60000);
const { data } = await getBggThing({ id: 6249, type: 'boardgame' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item.type).toEqual('boardgame');
});

it('gets thing with list of IDs and types', async () => {
jest.setTimeout(60000);
const { data } = await getBggThing({ id: [6249, 202976], type: ['boardgame', 'boardgameexpansion'] });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[0].type).toEqual('boardgame');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).item[1].type).toEqual('boardgameexpansion');
});
});

it('gets thread with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggThread({ id: 2427564 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).subject).toEqual('where to buy?');
describe('getBggThread', () => {
it('gets thread with given ID', async () => {
jest.setTimeout(60000);
const { data } = await getBggThread({ id: 2427564 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).subject).toEqual('where to buy?');
});
});

it('gets user with given name', async () => {
jest.setTimeout(60000);
const { data } = await getBggUser({ name: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).id).toEqual('1381959');
describe('getBggUser', () => {
it('gets user with given name', async () => {
jest.setTimeout(60000);
const { data } = await getBggUser({ name: 'Qrzy88' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((data as any).id).toEqual('1381959');
});
});
});
11 changes: 8 additions & 3 deletions src/wrappers/getBggCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type BggCollectionParams = {
version?: OneOrNothing;
subtype?: BggCollectionSubtype;
excludesubtype?: BggCollectionSubtype;
id?: number;
id?: number | number[] | string;
brief?: OneOrNothing;
stats?: OneOrNothing;
own?: ZeroOrOne;
Expand Down Expand Up @@ -52,5 +52,10 @@ export interface BggCollectionResponse {
[prop: string]: any;
}

export const getBggCollection = (params: BggCollectionParams): Promise<AxiosResponse<BggCollectionResponse>> =>
bggXmlApiClient.get('collection', params);
export const getBggCollection = (params: BggCollectionParams): Promise<AxiosResponse<BggCollectionResponse>> => {
const newParams = {
...params,
...(params.id && { id: Array.isArray(params.id) ? params.id.join(',') : params.id }),
};
return bggXmlApiClient.get('collection', newParams);
};
11 changes: 8 additions & 3 deletions src/wrappers/getBggFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BggFamilyType } from '../types';
import { AxiosResponse } from 'axios';

export type BggFamilyParams = {
id?: number;
id?: number | number[] | string;
type?: BggFamilyType;
};

Expand All @@ -14,5 +14,10 @@ export interface BggFamilyResponse {
[prop: string]: any;
}

export const getBggFamily = (params: BggFamilyParams): Promise<AxiosResponse<BggFamilyResponse>> =>
bggXmlApiClient.get('family', params);
export const getBggFamily = (params: BggFamilyParams): Promise<AxiosResponse<BggFamilyResponse>> => {
const newParams = {
...params,
...(params.id && { id: Array.isArray(params.id) ? params.id.join(',') : params.id }),
};
return bggXmlApiClient.get('family', newParams);
};
8 changes: 6 additions & 2 deletions src/wrappers/getBggPlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ export interface BggPlaysResponse {
[prop: string]: any;
}

export const getBggPlays = (params: BggPlaysParams): Promise<AxiosResponse<BggPlaysResponse>> =>
bggXmlApiClient.get('plays', params);
export const getBggPlays = (params: BggPlaysParams): Promise<AxiosResponse<BggPlaysResponse>> => {
if (!params.username && !(params.id && params.type)) {
throw new Error('You must specify either username or id and type');
}
return bggXmlApiClient.get('plays', params);
};
13 changes: 10 additions & 3 deletions src/wrappers/getBggSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { bggXmlApiClient } from '../client';
import { OneOrNothing } from '../types';
import { AxiosResponse } from 'axios';

export type SearchType = 'rpgitem' | 'videogame' | 'boardgame' | 'boardgameaccessory' | 'boardgameexpansion';

export type BggSearchParams = {
query: string;
type?: 'rpgitem' | 'videogame' | 'boardgame' | 'boardgameaccessory' | 'boardgameexpansion';
type?: SearchType | SearchType[] | string;
exact?: OneOrNothing;
};

Expand All @@ -15,5 +17,10 @@ export interface BggSearchResponse {
[prop: string]: any;
}

export const getBggSearch = (params: BggSearchParams): Promise<AxiosResponse<BggSearchResponse>> =>
bggXmlApiClient.get('search', params);
export const getBggSearch = (params: BggSearchParams): Promise<AxiosResponse<BggSearchResponse>> => {
const newParams = {
...params,
...(params.type && { type: Array.isArray(params.type) ? params.type.join(',') : params.type }),
};
return bggXmlApiClient.get('search', newParams);
};
14 changes: 10 additions & 4 deletions src/wrappers/getBggThing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ThingType, OneOrNothing } from '../types';
import { AxiosResponse } from 'axios';

export type BggThingParams = {
id?: number;
type?: ThingType;
id?: number | number[] | string;
type?: ThingType | ThingType[] | string;
versions?: OneOrNothing;
videos?: OneOrNothing;
stats?: OneOrNothing;
Expand All @@ -23,5 +23,11 @@ export interface BggThingResponse {
[prop: string]: any;
}

export const getBggThing = (params: BggThingParams): Promise<AxiosResponse<BggThingResponse>> =>
bggXmlApiClient.get('thing', params);
export const getBggThing = (params: BggThingParams): Promise<AxiosResponse<BggThingResponse>> => {
const newParams = {
...params,
...(params.id && { id: Array.isArray(params.id) ? params.id.join(',') : params.id }),
...(params.type && { type: Array.isArray(params.type) ? params.type.join(',') : params.type }),
};
return bggXmlApiClient.get('thing', newParams);
};
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"ES2017"
],
"module": "ES2015",
"moduleResolution": "node",
"esModuleInterop": true,
"declaration": true,
"outDir": "./lib",
"strict": true
Expand Down

0 comments on commit 4d79787

Please sign in to comment.