diff --git a/.babelrc b/.babelrc index c58af5b..69a5cad 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ -{ - "presets": [ - "@babel/preset-env", - "@babel/preset-typescript" - ] +{ + "presets": [ + "@babel/preset-env", + "@babel/preset-typescript" + ] } \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index 336ac09..a3d91d6 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,25 +1,24 @@ -The MIT License (MIT) -===================== - -Copyright © `2020` `D. "AtlasTheBot" Plaza` - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +# The MIT License (MIT) + +Copyright © `2022` `Atora Suunva` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/jest.config.js b/jest.config.js index 1fec5f1..c5827d6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,4 +3,4 @@ module.exports = { testEnvironment: 'node', testMatch: ['/test/*.spec.ts'], setupFiles: ['/test/jest.setup.ts'], -}; \ No newline at end of file +} diff --git a/readme.md b/readme.md index e6a34f8..0fd0d7a 100755 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ # `booru` -> *A node package to search boorus* +> _A node package to search boorus_ -[![CircleCI](https://img.shields.io/circleci/project/github/AtlasTheBot/booru.svg)](https://circleci.com/gh/AtlasTheBot/booru) ![npm](https://img.shields.io/npm/v/booru.svg) ![GitHub](https://img.shields.io/github/license/AtlasTheBot/booru.svg) ![Typescript typings](https://img.shields.io/badge/Typings-Typescript-informational.svg) +[![CircleCI](https://img.shields.io/circleci/project/github/AtoraSuunva/booru.svg)](https://circleci.com/gh/AtoraSuunva/booru) ![npm](https://img.shields.io/npm/v/booru.svg) ![GitHub](https://img.shields.io/github/license/AtoraSuunva/booru.svg) ![Typescript typings](https://img.shields.io/badge/Typings-Typescript-informational.svg) ## Features @@ -33,11 +33,11 @@ yarn add booru ```js const Booru = require('booru') -Booru.search('safebooru', ['glaceon'], { limit: 3, random: true }) - .then(posts => { - for (let post of posts) - console.log(post.fileUrl, post.postView) - }) +Booru.search('safebooru', ['glaceon'], { limit: 3, random: true }).then( + posts => { + for (let post of posts) console.log(post.fileUrl, post.postView) + }, +) // or (using alias support and creating boorus) const sb = Booru.forSite('sb') @@ -105,18 +105,22 @@ Why not? ## Contributors [BobbyWibowo](https://github.com/BobbyWibowo/booru) -> [Change from request-promise-native to snek-fetch](https://github.com/AtlasTheBot/booru/pull/9) + +> [Change from request-promise-native to snek-fetch](https://github.com/AtoraSuunva/booru/pull/9) [rubikscraft](https://github.com/rubikscraft/booru) -> [Add 2 new boorus (furry.booru.org/realbooru.com)](https://github.com/AtlasTheBot/booru/pull/17) -> [Various Derpibooru fixes](https://github.com/AtlasTheBot/booru/pull/19) + +> [Add 2 new boorus (furry.booru.org/realbooru.com)](https://github.com/AtoraSuunva/booru/pull/17) +> [Various Derpibooru fixes](https://github.com/AtoraSuunva/booru/pull/19) [Favna](https://github.com/favna/) -> [Add TypeScript declarations](https://github.com/AtlasTheBot/booru/pull/21) + +> [Add TypeScript declarations](https://github.com/AtoraSuunva/booru/pull/21) > Improve TypeScript port > Various other small fixes [negezor](https://github.com/negezor) -> [Add missing type information](https://github.com/AtlasTheBot/booru/pull/31) + +> [Add missing type information](https://github.com/AtoraSuunva/booru/pull/31) --- diff --git a/src/boorus/Booru.ts b/src/boorus/Booru.ts index 8d44e62..703a012 100644 --- a/src/boorus/Booru.ts +++ b/src/boorus/Booru.ts @@ -251,17 +251,16 @@ export class Booru { throw new BooruError(result.message || result.reason) } - // What the fuck gelbooru + // Gelbooru if (result['@attributes']) { const attributes = result['@attributes'] + if (attributes.count === '0' || !result.post) { result = [] + } else if (Array.isArray(result.post)) { + result = result.post } else { - if (Array.isArray(result.post)) { - result = result.post - } else { - result = [result.post] - } + result = [result.post] } } diff --git a/src/sites.json b/src/sites.json index 414153e..7e39442 100644 --- a/src/sites.json +++ b/src/sites.json @@ -1,217 +1,217 @@ -{ - "e621.net": { - "domain": "e621.net", - "aliases": [ - "e6", - "e621" - ], - "nsfw": true, - "api": { - "search": "/posts.json?", - "postView": "/post/show/" - }, - "random": true - }, - "e926.net": { - "domain": "e926.net", - "aliases": [ - "e9", - "e926" - ], - "nsfw": false, - "api": { - "search": "/posts.json?", - "postView": "/post/show/" - }, - "random": true, - "defaultTags": ["rating:safe"] - }, - "hypnohub.net": { - "domain": "hypnohub.net", - "aliases": [ - "hh", - "hypno", - "hypnohub" - ], - "nsfw": true, - "api": { - "search": "/post/index.json?", - "postView": "/post/show/" - }, - "random": true - }, - "danbooru.donmai.us": { - "domain": "danbooru.donmai.us", - "aliases": [ - "db", - "dan", - "danbooru" - ], - "nsfw": true, - "api": { - "search": "/posts.json?", - "postView": "/posts/" - }, - "random": true - }, - "konachan.com": { - "domain": "konachan.com", - "aliases": [ - "kc", - "konac", - "kcom" - ], - "nsfw": true, - "api": { - "search": "/post.json?", - "postView": "/post/show/" - }, - "random": true - }, - "konachan.net": { - "domain": "konachan.net", - "aliases": [ - "kn", - "konan", - "knet" - ], - "nsfw": false, - "api": { - "search": "/post.json?", - "postView": "/post/show/" - }, - "random": true - }, - "yande.re": { - "domain": "yande.re", - "aliases": [ - "yd", - "yand", - "yandere" - ], - "nsfw": true, - "api": { - "search": "/post.json?", - "postView": "/post/show/" - }, - "random": true - }, - "gelbooru.com": { - "domain": "gelbooru.com", - "aliases": [ - "gb", - "gel", - "gelbooru" - ], - "nsfw": true, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&json=1&id=" - }, - "paginate": "pid", - "random": false - }, - "rule34.xxx": { - "domain": "api.rule34.xxx", - "aliases": [ - "r34", - "rule34" - ], - "nsfw": true, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&json=1&id=" - }, - "paginate": "pid", - "random": false - }, - "safebooru.org": { - "domain": "safebooru.org", - "aliases": [ - "sb", - "safe", - "safebooru" - ], - "nsfw": false, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&json=1&id=" - }, - "paginate": "pid", - "random": false - }, - "tbib.org": { - "domain": "tbib.org", - "aliases": [ - "tb", - "tbib", - "big" - ], - "nsfw": false, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&json=1&id=" - }, - "paginate": "pid", - "random": false - }, - "xbooru.com": { - "domain": "xbooru.com", - "aliases": [ - "xb", - "xbooru" - ], - "nsfw": true, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&json=1&id=" - }, - "paginate": "pid", - "random": false - }, - "rule34.paheal.net": { - "domain": "rule34.paheal.net", - "type": "xml", - "aliases": [ - "pa", - "paheal" - ], - "nsfw": true, - "api": { - "search": "/api/danbooru/find_posts/index.xml?", - "postView": "/post/view/" - }, - "random": false - }, - "derpibooru.org": { - "domain": "derpibooru.org", - "type": "derpi", - "aliases": [ - "dp", - "derp", - "derpi", - "derpibooru" - ], - "nsfw": true, - "api": { - "search": "/api/v1/json/search/images?", - "postView": "/images/" - }, - "tagQuery": "q", - "random": "sf=random" - }, - "realbooru.com": { - "domain": "realbooru.com", - "aliases": [ - "rb", - "realbooru" - ], - "nsfw": true, - "api": { - "search": "/index.php?page=dapi&s=post&q=index&json=1&", - "postView": "/index.php?page=post&s=view&id=" - }, - "paginate": "pid", - "random": false - } -} +{ + "e621.net": { + "domain": "e621.net", + "aliases": [ + "e6", + "e621" + ], + "nsfw": true, + "api": { + "search": "/posts.json?", + "postView": "/post/show/" + }, + "random": true + }, + "e926.net": { + "domain": "e926.net", + "aliases": [ + "e9", + "e926" + ], + "nsfw": false, + "api": { + "search": "/posts.json?", + "postView": "/post/show/" + }, + "random": true, + "defaultTags": ["rating:safe"] + }, + "hypnohub.net": { + "domain": "hypnohub.net", + "aliases": [ + "hh", + "hypno", + "hypnohub" + ], + "nsfw": true, + "api": { + "search": "/post/index.json?", + "postView": "/post/show/" + }, + "random": true + }, + "danbooru.donmai.us": { + "domain": "danbooru.donmai.us", + "aliases": [ + "db", + "dan", + "danbooru" + ], + "nsfw": true, + "api": { + "search": "/posts.json?", + "postView": "/posts/" + }, + "random": true + }, + "konachan.com": { + "domain": "konachan.com", + "aliases": [ + "kc", + "konac", + "kcom" + ], + "nsfw": true, + "api": { + "search": "/post.json?", + "postView": "/post/show/" + }, + "random": true + }, + "konachan.net": { + "domain": "konachan.net", + "aliases": [ + "kn", + "konan", + "knet" + ], + "nsfw": false, + "api": { + "search": "/post.json?", + "postView": "/post/show/" + }, + "random": true + }, + "yande.re": { + "domain": "yande.re", + "aliases": [ + "yd", + "yand", + "yandere" + ], + "nsfw": true, + "api": { + "search": "/post.json?", + "postView": "/post/show/" + }, + "random": true + }, + "gelbooru.com": { + "domain": "gelbooru.com", + "aliases": [ + "gb", + "gel", + "gelbooru" + ], + "nsfw": true, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&json=1&id=" + }, + "paginate": "pid", + "random": false + }, + "rule34.xxx": { + "domain": "api.rule34.xxx", + "aliases": [ + "r34", + "rule34" + ], + "nsfw": true, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&json=1&id=" + }, + "paginate": "pid", + "random": false + }, + "safebooru.org": { + "domain": "safebooru.org", + "aliases": [ + "sb", + "safe", + "safebooru" + ], + "nsfw": false, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&json=1&id=" + }, + "paginate": "pid", + "random": false + }, + "tbib.org": { + "domain": "tbib.org", + "aliases": [ + "tb", + "tbib", + "big" + ], + "nsfw": false, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&json=1&id=" + }, + "paginate": "pid", + "random": false + }, + "xbooru.com": { + "domain": "xbooru.com", + "aliases": [ + "xb", + "xbooru" + ], + "nsfw": true, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&json=1&id=" + }, + "paginate": "pid", + "random": false + }, + "rule34.paheal.net": { + "domain": "rule34.paheal.net", + "type": "xml", + "aliases": [ + "pa", + "paheal" + ], + "nsfw": true, + "api": { + "search": "/api/danbooru/find_posts/index.xml?", + "postView": "/post/view/" + }, + "random": false + }, + "derpibooru.org": { + "domain": "derpibooru.org", + "type": "derpi", + "aliases": [ + "dp", + "derp", + "derpi", + "derpibooru" + ], + "nsfw": true, + "api": { + "search": "/api/v1/json/search/images?", + "postView": "/images/" + }, + "tagQuery": "q", + "random": "sf=random" + }, + "realbooru.com": { + "domain": "realbooru.com", + "aliases": [ + "rb", + "realbooru" + ], + "nsfw": true, + "api": { + "search": "/index.php?page=dapi&s=post&q=index&json=1&", + "postView": "/index.php?page=post&s=view&id=" + }, + "paginate": "pid", + "random": false + } +} diff --git a/src/structures/InternalSearchParameters.ts b/src/structures/InternalSearchParameters.ts index 20c2cf0..2ac2cf8 100644 --- a/src/structures/InternalSearchParameters.ts +++ b/src/structures/InternalSearchParameters.ts @@ -1,19 +1,19 @@ -/** - * @packageDocumentation - * @module Structures - */ - -import SearchParameters from './SearchParameters' - -/** - * Interface for {@link Booru}'s **private internal** search params pls no use - */ - -export default interface InternalSearchParameters extends SearchParameters { - /** The uri to override with, if provided */ - uri?: string | null - /** If `order:random` should be faked */ - fakeLimit?: number - /** The tags used in the search */ - tags?: string[] | string -} +/** + * @packageDocumentation + * @module Structures + */ + +import SearchParameters from './SearchParameters' + +/** + * Interface for {@link Booru}'s **private internal** search params pls no use + */ + +export default interface InternalSearchParameters extends SearchParameters { + /** The uri to override with, if provided */ + uri?: string | null + /** If `order:random` should be faked */ + fakeLimit?: number + /** The tags used in the search */ + tags?: string[] | string +} diff --git a/src/structures/SiteInfo.ts b/src/structures/SiteInfo.ts index 7a828f1..dd7710e 100644 --- a/src/structures/SiteInfo.ts +++ b/src/structures/SiteInfo.ts @@ -1,34 +1,34 @@ -/** - * @packageDocumentation - * @module Structures - */ - -import SiteApi from './SiteApi' - -/** - * Represents the info needed to create a new {@link Site} - *

Same properties as {@link Site}, but some optional

- *

Mostly just here to reflect what sites.json should look like - */ -export default interface SiteInfo { - /** The domain of the Site (the "google.com" part of "https://google.com/foo") */ - domain: string - /** The type of this site (json/xml/derpi) */ - type: string - /** The aliases of this site */ - aliases: string[] - /** If this site serves NSFW posts or not */ - nsfw: boolean - /** An object representing the api of this site */ - api: SiteApi - /** The url query param to paginate on the site */ - paginate?: string - /** If the site supports `order:random` */ - random: boolean | string - /** The url query param for tags */ - tagQuery?: string - /** If this site supports only http:// */ - insecure?: boolean - /** Tags to add to every request, if not included */ - defaultTags?: string[] -} +/** + * @packageDocumentation + * @module Structures + */ + +import SiteApi from './SiteApi' + +/** + * Represents the info needed to create a new {@link Site} + *

Same properties as {@link Site}, but some optional

+ *

Mostly just here to reflect what sites.json should look like + */ +export default interface SiteInfo { + /** The domain of the Site (the "google.com" part of "https://google.com/foo") */ + domain: string + /** The type of this site (json/xml/derpi) */ + type: string + /** The aliases of this site */ + aliases: string[] + /** If this site serves NSFW posts or not */ + nsfw: boolean + /** An object representing the api of this site */ + api: SiteApi + /** The url query param to paginate on the site */ + paginate?: string + /** If the site supports `order:random` */ + random: boolean | string + /** The url query param for tags */ + tagQuery?: string + /** If this site supports only http:// */ + insecure?: boolean + /** Tags to add to every request, if not included */ + defaultTags?: string[] +} diff --git a/test/derpibooru.spec.ts b/test/derpibooru.spec.ts index 31b733c..52fd349 100644 --- a/test/derpibooru.spec.ts +++ b/test/derpibooru.spec.ts @@ -1,36 +1,36 @@ -import Booru, { BooruClass, search, sites } from '../src/index' -import Post from '../src/structures/Post' -import SearchResults from '../src/structures/SearchResults' - -let tag1: string -let site: string - -beforeEach(() => { - site = 'dp' - tag1 = 'girl' -}) - -describe('Using instantiation method', () => { - let danbooru: BooruClass - beforeEach(() => { - danbooru = Booru(site) - }) - - it('should return an image', async() => { - const searchResult: SearchResults = await danbooru.search([tag1]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('derpibooru.org') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) - -describe('Using fancy pants method', () => { - it('should return an image', async() => { - const searchResult = await search(site, [tag1]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('derpibooru.org') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) +import Booru, { BooruClass, search, sites } from '../src/index' +import Post from '../src/structures/Post' +import SearchResults from '../src/structures/SearchResults' + +let tag1: string +let site: string + +beforeEach(() => { + site = 'dp' + tag1 = 'girl' +}) + +describe('Using instantiation method', () => { + let danbooru: BooruClass + beforeEach(() => { + danbooru = Booru(site) + }) + + it('should return an image', async() => { + const searchResult: SearchResults = await danbooru.search([tag1]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('derpibooru.org') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) + +describe('Using fancy pants method', () => { + it('should return an image', async() => { + const searchResult = await search(site, [tag1]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('derpibooru.org') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) diff --git a/test/e621.spec.ts b/test/e621.spec.ts index f83df34..4a17f69 100644 --- a/test/e621.spec.ts +++ b/test/e621.spec.ts @@ -1,38 +1,38 @@ -import Booru, { BooruClass, search, sites } from '../src/index' -import Post from '../src/structures/Post' -import SearchResults from '../src/structures/SearchResults' - -let tag1: string -let tag2: string -let site: string - -beforeEach(() => { - site = 'e6' - tag1 = 'girl' - tag2 = '-cub' -}) - -describe('Using instantiation method', () => { - let danbooru: BooruClass - beforeEach(() => { - danbooru = Booru(site) - }) - - it('should return an image', async() => { - const searchResult: SearchResults = await danbooru.search([tag1, tag2]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('e621.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) - -describe('Using fancy pants method', () => { - it('should return an image', async() => { - const searchResult = await search(site, [tag1, tag2]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('e621.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) +import Booru, { BooruClass, search, sites } from '../src/index' +import Post from '../src/structures/Post' +import SearchResults from '../src/structures/SearchResults' + +let tag1: string +let tag2: string +let site: string + +beforeEach(() => { + site = 'e6' + tag1 = 'girl' + tag2 = '-cub' +}) + +describe('Using instantiation method', () => { + let danbooru: BooruClass + beforeEach(() => { + danbooru = Booru(site) + }) + + it('should return an image', async() => { + const searchResult: SearchResults = await danbooru.search([tag1, tag2]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('e621.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) + +describe('Using fancy pants method', () => { + it('should return an image', async() => { + const searchResult = await search(site, [tag1, tag2]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('e621.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) diff --git a/test/e926.spec.ts b/test/e926.spec.ts index b82261f..6b2ae6e 100644 --- a/test/e926.spec.ts +++ b/test/e926.spec.ts @@ -1,38 +1,38 @@ -import Booru, { BooruClass, search, sites } from '../src/index' -import Post from '../src/structures/Post' -import SearchResults from '../src/structures/SearchResults' - -let tag1: string -let tag2: string -let site: string - -beforeEach(() => { - site = 'e9' - tag1 = 'glaceon' - tag2 = 'flareon' -}) - -describe('Using instantiation method', () => { - let danbooru: BooruClass - beforeEach(() => { - danbooru = Booru(site) - }) - - it('should return an image', async() => { - const searchResult: SearchResults = await danbooru.search([tag1, tag2]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('e926.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) - -describe('Using fancy pants method', () => { - it('should return an image', async() => { - const searchResult = await search(site, [tag1, tag2]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('e926.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) +import Booru, { BooruClass, search, sites } from '../src/index' +import Post from '../src/structures/Post' +import SearchResults from '../src/structures/SearchResults' + +let tag1: string +let tag2: string +let site: string + +beforeEach(() => { + site = 'e9' + tag1 = 'glaceon' + tag2 = 'flareon' +}) + +describe('Using instantiation method', () => { + let danbooru: BooruClass + beforeEach(() => { + danbooru = Booru(site) + }) + + it('should return an image', async() => { + const searchResult: SearchResults = await danbooru.search([tag1, tag2]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('e926.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) + +describe('Using fancy pants method', () => { + it('should return an image', async() => { + const searchResult = await search(site, [tag1, tag2]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('e926.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) diff --git a/test/hypnohub.spec.ts b/test/hypnohub.spec.ts index 776c850..787b566 100644 --- a/test/hypnohub.spec.ts +++ b/test/hypnohub.spec.ts @@ -1,37 +1,37 @@ -import Booru, { BooruClass, search, sites } from '../src/index' -import Post from '../src/structures/Post' -import SearchResults from '../src/structures/SearchResults' - -let tag1: string -let site: string - -beforeEach(() => { - site = 'hh' - tag1 = 'cat' -}) - -// Ignore since I seem to be getting hit by DDoS protection on the api endpoint? -describe.skip('Using instantiation method', () => { - let booruClass: BooruClass - beforeEach(() => { - booruClass = Booru(site) - }) - - it('should return an image', async () => { - const searchResult: SearchResults = await booruClass.search([tag1]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('hypnohub.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) - -describe.skip('Using fancy pants method', () => { - it('should return an image', async () => { - const searchResult = await search(site, [tag1]) - const image: Post = searchResult[0] - expect(searchResult.booru.domain).toBe('hypnohub.net') - expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) - expect(typeof image.fileUrl).toBe('string') - }) -}) +import Booru, { BooruClass, search, sites } from '../src/index' +import Post from '../src/structures/Post' +import SearchResults from '../src/structures/SearchResults' + +let tag1: string +let site: string + +beforeEach(() => { + site = 'hh' + tag1 = 'cat' +}) + +// Ignore since I seem to be getting hit by DDoS protection on the api endpoint? +describe.skip('Using instantiation method', () => { + let booruClass: BooruClass + beforeEach(() => { + booruClass = Booru(site) + }) + + it('should return an image', async () => { + const searchResult: SearchResults = await booruClass.search([tag1]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('hypnohub.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) + +describe.skip('Using fancy pants method', () => { + it('should return an image', async () => { + const searchResult = await search(site, [tag1]) + const image: Post = searchResult[0] + expect(searchResult.booru.domain).toBe('hypnohub.net') + expect(searchResult.booru.site).toMatchObject(sites[searchResult.booru.domain]) + expect(typeof image.fileUrl).toBe('string') + }) +}) diff --git a/test/util.spec.ts b/test/util.spec.ts index 46a7652..8c23699 100644 --- a/test/util.spec.ts +++ b/test/util.spec.ts @@ -1,47 +1,47 @@ -import path from 'path' -import { BooruClass, BooruError, resolveSite, sites } from '../src' -import Site from '../src/structures/Site' - -let site: string - -beforeEach(() => { - site = 'db' -}) - -describe('Check resolveSite', () => { - it('should resolve alias to host', () => { - expect(resolveSite(site)).toBe('danbooru.donmai.us') - }) -}) - -describe('check BooruError', () => { - it('should resolve to a BooruError', () => { - const booruError = new BooruError() - expect(booruError.name).toBe('BooruError') - expect(booruError.stack).toContain(path.basename(__filename)) - }) -}) - -describe('check BooruClass', () => { - it('should resolve to a BooruClass', () => { - const SiteData: Site = { - aliases: ['sb', 'safe', 'safebooru'], - api: {search: '/index.php?page=dapi&s=post&q=index&json=1&', postView: '/index.php?page=post&s=view&json=1&id='}, - domain: 'safebooru.org', - nsfw: false, - random: false, - paginate: 'pid', - } - const booruClass = new BooruClass(SiteData) - - expect(booruClass.domain).toBe('safebooru.org') - expect(booruClass.site).toMatchObject(SiteData) - }) -}) - -describe('check sites', () => { - it('should support 15 sites', () => { - const map = sites - expect(Object.keys(map)).toHaveLength(15) - }) -}) +import path from 'path' +import { BooruClass, BooruError, resolveSite, sites } from '../src' +import Site from '../src/structures/Site' + +let site: string + +beforeEach(() => { + site = 'db' +}) + +describe('Check resolveSite', () => { + it('should resolve alias to host', () => { + expect(resolveSite(site)).toBe('danbooru.donmai.us') + }) +}) + +describe('check BooruError', () => { + it('should resolve to a BooruError', () => { + const booruError = new BooruError() + expect(booruError.name).toBe('BooruError') + expect(booruError.stack).toContain(path.basename(__filename)) + }) +}) + +describe('check BooruClass', () => { + it('should resolve to a BooruClass', () => { + const SiteData: Site = { + aliases: ['sb', 'safe', 'safebooru'], + api: {search: '/index.php?page=dapi&s=post&q=index&json=1&', postView: '/index.php?page=post&s=view&json=1&id='}, + domain: 'safebooru.org', + nsfw: false, + random: false, + paginate: 'pid', + } + const booruClass = new BooruClass(SiteData) + + expect(booruClass.domain).toBe('safebooru.org') + expect(booruClass.site).toMatchObject(SiteData) + }) +}) + +describe('check sites', () => { + it('should support 15 sites', () => { + const map = sites + expect(Object.keys(map)).toHaveLength(15) + }) +})