Skip to content

Commit 0b14e8d

Browse files
authored
fix: export models (#290)
1 parent fc4a31e commit 0b14e8d

File tree

6 files changed

+2993
-398
lines changed

6 files changed

+2993
-398
lines changed

__tests__/basic.test.js renamed to __tests__/basic.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
/// <reference types="jest" />
2-
3-
const { default: TCGdex, Query } = require("../src/tcgdex")
4-
import fetch from 'node-fetch'
1+
import { expect, test, vi } from 'vitest'
2+
import TCGdex, { Query } from '../src/tcgdex'
53

64
// change timeout of execution
7-
jest.setTimeout(120000)
5+
vi.setConfig({ testTimeout: 120000 })
86

9-
const fakeFetch = (response, status = 200) => jest.fn(() =>
7+
const fakeFetch = (response: any, status = 200) => vi.fn(() =>
108
Promise.resolve({
119
status: status,
12-
json: () => Promise.resolve(response),
10+
json: () => Promise.resolve(response)
1311
})
14-
);
12+
)
1513

1614
test('Basic test', async () => {
1715
const tcgdex = new TCGdex('en')
18-
TCGdex.fetch = fakeFetch({ ok: true })
16+
TCGdex.fetch = fakeFetch({ ok: true }) as any
1917
const res = await tcgdex.fetch('cards', 'basic-test')
2018
expect(res).toEqual({ ok: true })
2119
expect(TCGdex.fetch).toHaveBeenCalledTimes(1)
2220
})
2321

2422
test('endpoint errors', async () => {
2523
const tcgdex = new TCGdex('en')
26-
TCGdex.fetch = fakeFetch({ ok: 'a' })
24+
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
2725
await expect(tcgdex.fetch('non existing endpoint')).rejects.toThrow()
2826
await expect(tcgdex.fetch()).rejects.toThrow()
2927
})
@@ -70,7 +68,7 @@ test(`test get set from card`, async () => {
7068
TCGdex.fetch = fetch
7169

7270
expect(
73-
await (await tcgdex.card.get('swsh1-136')).getSet()
71+
await (await tcgdex.card.get('swsh1-136'))!.getSet()
7472
).toBeTruthy()
7573
})
7674

@@ -79,7 +77,7 @@ test(`test get serie from set`, async () => {
7977
TCGdex.fetch = fetch
8078

8179
expect(
82-
await (await tcgdex.set.get('swsh1')).getSerie()
80+
await (await tcgdex.set.get('swsh1'))!.getSerie()
8381
).toBeTruthy()
8482
})
8583

__tests__/deprecated.test.js renamed to __tests__/deprecated.test.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
const TCGdex = require("../src/tcgdex").default
2-
const fetch = require('node-fetch')
1+
import { expect, test, vi } from 'vitest'
2+
import TCGdex from '../src/tcgdex'
33

4-
const fakeFetch = (response, status = 200) => jest.fn(() =>
4+
// change timeout of execution
5+
vi.setConfig({ testTimeout: 120000 })
6+
7+
const fakeFetch = (response, status = 200) => vi.fn(() =>
58
Promise.resolve({
69
status: status,
710
json: () => Promise.resolve(response),
811
})
9-
);
10-
11-
12+
)
1213

1314
test('Basic test', async () => {
1415
const tcgdex = new TCGdex('en')
15-
TCGdex.fetch = fakeFetch({ok: true})
16+
TCGdex.fetch = fakeFetch({ ok: true }) as any
1617
const res = await tcgdex.fetch('cards', 'basic-test')
17-
expect(res).toEqual({ok: true})
18+
expect(res).toEqual({ ok: true })
1819
expect(TCGdex.fetch).toHaveBeenCalledTimes(1)
1920
})
2021

2122
test('Cache test', async () => {
2223
const tcgdex = new TCGdex('en')
23-
TCGdex.fetch = fakeFetch({ok: 'a'})
24+
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
2425
const res1 = await tcgdex.fetch('cards', 'cache-test')
25-
expect(res1).toEqual({ok: 'a'})
26-
TCGdex.fetch = fakeFetch({ok: 'b'})
26+
expect(res1).toEqual({ ok: 'a' })
27+
TCGdex.fetch = fakeFetch({ ok: 'b' }) as any
2728
const res2 = await tcgdex.fetch('cards', 'cache-test')
28-
expect(res2).toEqual({ok: 'a'})
29+
expect(res2).toEqual({ ok: 'a' })
2930
})
3031

3132
test('endpoint errors', async () => {
3233
const tcgdex = new TCGdex('en')
33-
TCGdex.fetch = fakeFetch({ok: 'a'})
34+
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
3435
await expect(tcgdex.fetch('non existing endpoint')).rejects.toThrow()
3536
await expect(tcgdex.fetch()).rejects.toThrow()
3637
})
3738

3839
test('404 test', async () => {
3940
const tcgdex = new TCGdex('en')
40-
TCGdex.fetch = fakeFetch(undefined, 404)
41+
TCGdex.fetch = fakeFetch(undefined, 404) as any
4142
expect(
4243
await tcgdex.fetch('cards', '404-test')
4344
).not.toBeDefined()
@@ -47,15 +48,15 @@ test('test real endpoints', async () => {
4748
const tcgdex = new TCGdex('en')
4849
TCGdex.fetch = fetch
4950
const endpoints = [
50-
{endpoint: 'fetchCard', params: ['swsh1-1']},
51-
{endpoint: 'fetchCard', params: ['1', 'Sword & Shield']},
52-
{endpoint: 'fetchCards', params: ['swsh1']},
53-
{endpoint: 'fetchCards', params: []},
54-
{endpoint: 'fetchSet', params: ['swsh1']},
55-
{endpoint: 'fetchSets', params: ['swsh']},
56-
{endpoint: 'fetchSets', params: []},
57-
{endpoint: 'fetchSeries', params: []},
58-
{endpoint: 'fetchSerie', params: ['swsh']},
51+
{ endpoint: 'fetchCard', params: ['swsh1-1'] },
52+
{ endpoint: 'fetchCard', params: ['1', 'Sword & Shield'] },
53+
{ endpoint: 'fetchCards', params: ['swsh1'] },
54+
{ endpoint: 'fetchCards', params: [] },
55+
{ endpoint: 'fetchSet', params: ['swsh1'] },
56+
{ endpoint: 'fetchSets', params: ['swsh'] },
57+
{ endpoint: 'fetchSets', params: [] },
58+
{ endpoint: 'fetchSeries', params: [] },
59+
{ endpoint: 'fetchSerie', params: ['swsh'] },
5960
]
6061

6162
for await (const item of endpoints) {

0 commit comments

Comments
 (0)