diff options
| author | Ritesh Ghosh <[email protected]> | 2024-10-06 01:13:23 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-06 01:13:23 +0530 |
| commit | 46f688ac12a99b8fb145b0745dd4cc6babff1e1e (patch) | |
| tree | 9560dd057822069a2162ef01a1118f3ac05e6d07 /test | |
| parent | 55810ccf2372209f9b46c96ac12811e5a05f7961 (diff) | |
| download | aniwatch-api-46f688ac12a99b8fb145b0745dd4cc6babff1e1e.tar.xz aniwatch-api-46f688ac12a99b8fb145b0745dd4cc6babff1e1e.zip | |
Aniwatch API Version 2 (#66)
BREAKING CHANGE:
* chore: remove files that are not necessary for api v2
* test: update existing tests to use pkg
* feat: organized aniwatch api envs and add more info about them
* feat: update tsconfig to include strict noUnsed params
* feat(api homepage): revamp api home page
* feat: update wani kuni image
* feat: add dot img
* feat: use hono cors
* feat: use hono rate limiter
* build: remove unnecessary deps, add ones needed and update description
* feat: add hianime routes and their handlers
* feat: update vercel deployment file
* docs: update logo and scraper docs, add envs section
* feat: update main server file
* feat: update peronal deployments caution section
Diffstat (limited to 'test')
| -rw-r--r-- | test/animeAboutInfo.test.ts | 10 | ||||
| -rw-r--r-- | test/animeCategory.test.ts | 10 | ||||
| -rw-r--r-- | test/animeEpisodeSrcs.test.ts | 19 | ||||
| -rw-r--r-- | test/animeEpisodes.test.ts | 10 | ||||
| -rw-r--r-- | test/animeGenre.test.ts | 12 | ||||
| -rw-r--r-- | test/animeProducer.test.ts | 11 | ||||
| -rw-r--r-- | test/animeSearch.test.ts | 14 | ||||
| -rw-r--r-- | test/animeSearchSuggestion.test.ts | 10 | ||||
| -rw-r--r-- | test/episodeServers.test.ts | 10 | ||||
| -rw-r--r-- | test/estimatedSchedule.test.ts | 20 | ||||
| -rw-r--r-- | test/homePage.test.ts | 7 |
11 files changed, 90 insertions, 43 deletions
diff --git a/test/animeAboutInfo.test.ts b/test/animeAboutInfo.test.ts index 2cdc0cb..82fe97d 100644 --- a/test/animeAboutInfo.test.ts +++ b/test/animeAboutInfo.test.ts @@ -1,8 +1,12 @@ +import { HiAnime } from "aniwatch"; import { expect, test } from "vitest"; -import { scrapeAnimeAboutInfo } from "../src/parsers/index.js"; -test("returns information about an anime", async () => { - const data = await scrapeAnimeAboutInfo("steinsgate-3"); +const animeId = "steinsgate-3"; + +// npx vitest run animeAboutInfo.test.ts +test(`GET /api/v2/hianime/anime/${animeId}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getInfo(animeId); expect(data.anime.info.name).not.toEqual(null); expect(data.recommendedAnimes).not.toEqual([]); diff --git a/test/animeCategory.test.ts b/test/animeCategory.test.ts index 55ad873..045b0f9 100644 --- a/test/animeCategory.test.ts +++ b/test/animeCategory.test.ts @@ -1,8 +1,12 @@ import { expect, test } from "vitest"; -import { scrapeAnimeCategory } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns animes belonging to a category", async () => { - const data = await scrapeAnimeCategory("subbed-anime"); +const category = "subbed-anime"; + +// npx vitest run animeCategory.test.ts +test(`GET /api/v2/hianime/category/${category}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getCategoryAnime(category); expect(data.animes).not.toEqual([]); expect(data.genres).not.toEqual([]); diff --git a/test/animeEpisodeSrcs.test.ts b/test/animeEpisodeSrcs.test.ts index 1c6f160..d8db0ed 100644 --- a/test/animeEpisodeSrcs.test.ts +++ b/test/animeEpisodeSrcs.test.ts @@ -1,13 +1,18 @@ import { expect, test } from "vitest"; -import { scrapeAnimeEpisodeSources } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns anime episode streaming link(s)", async () => { - const data = await scrapeAnimeEpisodeSources( - "steinsgate-3?ep=230", - "hd-1", - "sub" +const animeEpisodeId = "steinsgate-3?ep=230"; +const server = "hd-1"; +const category = "sub"; + +// npx vitest run animeEpisodeSrcs.test.ts +test(`GET /api/v2/hianime/episode/sources?animeEpisodeId=${animeEpisodeId}&server=${server}&category=${category}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getEpisodeSources( + animeEpisodeId, + server, + category ); expect(data.sources).not.toEqual([]); - // expect(data) }); diff --git a/test/animeEpisodes.test.ts b/test/animeEpisodes.test.ts index f727056..fbe75ae 100644 --- a/test/animeEpisodes.test.ts +++ b/test/animeEpisodes.test.ts @@ -1,8 +1,12 @@ +import { HiAnime } from "aniwatch"; import { expect, test } from "vitest"; -import { scrapeAnimeEpisodes } from "../src/parsers/index.js"; -test("returns episodes info of an anime", async () => { - const data = await scrapeAnimeEpisodes("steinsgate-3"); +const animeId = "steinsgate-3"; + +// npx vitest run animeEpisodes.test.ts +test(`GET /api/v2/hianime/anime/${animeId}/episodes`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getEpisodes(animeId); expect(data.totalEpisodes).not.toEqual(0); expect(data.episodes).not.toEqual([]); diff --git a/test/animeGenre.test.ts b/test/animeGenre.test.ts index 9e6610a..f08ad1b 100644 --- a/test/animeGenre.test.ts +++ b/test/animeGenre.test.ts @@ -1,8 +1,14 @@ import { expect, test } from "vitest"; -import { scrapeGenreAnime } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns animes belonging to a genre", async () => { - const data = await scrapeGenreAnime("shounen", 2); +const genreName = "shounen"; +const page = 2; + +// npx vitest run animeGenre.test.ts +test(`GET /api/v2/hianime/genre/${genreName}?page=${page}`, async () => { + const hianime = new HiAnime.Scraper(); + + const data = await hianime.getGenreAnime(genreName, page); expect(data.animes).not.toEqual([]); expect(data.genres).not.toEqual([]); diff --git a/test/animeProducer.test.ts b/test/animeProducer.test.ts index ae17c83..53f0d28 100644 --- a/test/animeProducer.test.ts +++ b/test/animeProducer.test.ts @@ -1,8 +1,13 @@ import { expect, test } from "vitest"; -import { scrapeProducerAnimes } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns animes produced by a producer", async () => { - const data = await scrapeProducerAnimes("toei-animation", 2); +const producerName = "toei-animation"; +const page = 2; + +// npx vitest run animeProducer.test.ts +test(`GET /api/v2/hianime/producer/${producerName}?page=${page}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getProducerAnimes(producerName, page); expect(data.animes).not.toEqual([]); expect(data.topAiringAnimes).not.toEqual([]); diff --git a/test/animeSearch.test.ts b/test/animeSearch.test.ts index efd2641..dac66cb 100644 --- a/test/animeSearch.test.ts +++ b/test/animeSearch.test.ts @@ -1,8 +1,16 @@ import { expect, test } from "vitest"; -import { scrapeAnimeSearch } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns animes related to search query", async () => { - const data = await scrapeAnimeSearch("monster", 2); +const query = "monster"; +const page = 1; +const filter: HiAnime.SearchFilters = { + genres: "seinen,psychological", +}; + +// npx vitest run animeSearch.test.ts +test(`GET /api/v2/hianime/search?q=${query}&page=${page}&genres=${filter.genres}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.search(query, page, filter); expect(data.animes).not.toEqual([]); expect(data.mostPopularAnimes).not.toEqual([]); diff --git a/test/animeSearchSuggestion.test.ts b/test/animeSearchSuggestion.test.ts index f3a875a..5957528 100644 --- a/test/animeSearchSuggestion.test.ts +++ b/test/animeSearchSuggestion.test.ts @@ -1,8 +1,12 @@ import { expect, test } from "vitest"; -import { scrapeAnimeSearchSuggestion } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns animes search suggestions related to search query", async () => { - const data = await scrapeAnimeSearchSuggestion("one piece"); +const query = "one piece"; + +// npx vitest run animeSearchSuggestion.test.ts +test(`GET /api/v2/hianime/search/suggestion?q=${query}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.searchSuggestions(query); expect(data.suggestions).not.toEqual([]); }); diff --git a/test/episodeServers.test.ts b/test/episodeServers.test.ts index 73cc5ca..c044e6c 100644 --- a/test/episodeServers.test.ts +++ b/test/episodeServers.test.ts @@ -1,8 +1,12 @@ import { expect, test } from "vitest"; -import { scrapeEpisodeServers } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns episode source servers", async () => { - const data = await scrapeEpisodeServers("steinsgate-0-92?ep=2055"); +const animeEpisodeId = "steinsgate-0-92?ep=2055"; + +// npx vitest run episodeServers.test.ts +test(`GET /api/v2/hianime/episode/servers?animeEpisodeId=${animeEpisodeId}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getEpisodeServers(animeEpisodeId); expect(data.episodeId).not.toEqual(null); expect(data.episodeNo).not.toEqual(0); diff --git a/test/estimatedSchedule.test.ts b/test/estimatedSchedule.test.ts index 40b6956..1e8e086 100644 --- a/test/estimatedSchedule.test.ts +++ b/test/estimatedSchedule.test.ts @@ -1,15 +1,17 @@ import { expect, test } from "vitest"; -import { scrapeEstimatedSchedule } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -function padZero(num: number) { - return num < 10 ? `0${num}` : num.toString(); -} +const padZero = (num: number) => (num < 10 ? `0${num}` : num.toString()); -test("returns estimated schedule anime release", async () => { - const d = new Date(); - const data = await scrapeEstimatedSchedule( - `${d.getFullYear()}-${padZero(d.getMonth() + 1)}-${padZero(d.getDate())}` - ); +const d = new Date(); +const date = `${d.getFullYear()}-${padZero(d.getMonth() + 1)}-${padZero( + d.getDate() +)}`; + +// npx vitest run estimatedSchedule.test.ts +test(`GET /api/v2/hianime/schedule?date=${date}`, async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getEstimatedSchedule(date); expect(data.scheduledAnimes).not.toEqual([]); }); diff --git a/test/homePage.test.ts b/test/homePage.test.ts index 25b409c..a5f9e8f 100644 --- a/test/homePage.test.ts +++ b/test/homePage.test.ts @@ -1,8 +1,9 @@ import { expect, test } from "vitest"; -import { scrapeHomePage } from "../src/parsers/index.js"; +import { HiAnime } from "aniwatch"; -test("returns anime information present in homepage", async () => { - const data = await scrapeHomePage(); +test("GET /api/v2/hianime/home", async () => { + const hianime = new HiAnime.Scraper(); + const data = await hianime.getHomePage(); expect(data.spotlightAnimes).not.toEqual([]); expect(data.trendingAnimes).not.toEqual([]); |
