furtrack-api 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/.github/workflows/node.js.yml +31 -0
- package/.github/workflows/npm-publish.yml +33 -0
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/jest.config.js +6 -0
- package/package.json +17 -0
- package/src/index.js +207 -0
- package/src/index.test.js +79 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "main" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "main" ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [18.x, 20.x, 22.x]
|
|
20
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
- run: npm test
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm publish
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 blumlaut
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# furtrack-api
|
|
2
|
+
|
|
3
|
+
An unofficial Node.js package for accessing the Furtrack API.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Fetch posts, users, tags, albums, and thumbnails from Furtrack
|
|
9
|
+
- Supports API key authentication
|
|
10
|
+
- Customizable HTTP headers (e.g., User-Agent)
|
|
11
|
+
- Tag parsing and filtering utilities
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install furtrack-api
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const FurtrackAPI = require('furtrack-api');
|
|
23
|
+
|
|
24
|
+
// Basic usage
|
|
25
|
+
const api = new FurtrackAPI();
|
|
26
|
+
|
|
27
|
+
// With API key and custom headers
|
|
28
|
+
const apiWithAuth = new FurtrackAPI({
|
|
29
|
+
apiKey: 'YOUR_API_KEY',
|
|
30
|
+
headers: {
|
|
31
|
+
'User-Agent': 'MyCustomAgent/1.0',
|
|
32
|
+
'X-Custom-Header': 'foobar'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Set or update API key later
|
|
37
|
+
api.setApiKey('NEW_API_KEY');
|
|
38
|
+
|
|
39
|
+
// Set or merge additional headers
|
|
40
|
+
api.setHeaders({
|
|
41
|
+
'User-Agent': 'AnotherAgent/2.0'
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Fetch a user
|
|
45
|
+
api.getUser('username').then(user => {
|
|
46
|
+
console.log(user);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
api.getPost(1337).then(post => {
|
|
50
|
+
console.log(post);
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// fetch a user's posts
|
|
54
|
+
api.getPostsByUser('username').then(posts => {
|
|
55
|
+
console.log(posts);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Fetch posts by tag with pagination
|
|
59
|
+
api.getPostsByTag('1:Fluffy', 2).then(posts => {
|
|
60
|
+
console.log(posts);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Fetch a user's liked posts
|
|
64
|
+
api.getLikes('username').then(posts => {
|
|
65
|
+
console.log(posts);
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Fetch a post's thumbnail URL
|
|
69
|
+
api.getThumbnail(12345).then(url => {
|
|
70
|
+
console.log(url);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Fetch a user's album.
|
|
74
|
+
api.getAlbum('username', 'albumid').then(album => {
|
|
75
|
+
console.log(album)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Functions which return a list of arrays additional support a page argument, FurTrack generally paginates albums longer than 200 images, by default only the first page is retrieved.
|
|
81
|
+
|
|
82
|
+
## Tag Utilities
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
// Parse a tag string
|
|
86
|
+
const parsed = api.parseTag('1:Fluffy');
|
|
87
|
+
// => { type: 'character', value: 'Fluffy' }
|
|
88
|
+
|
|
89
|
+
// Filter tags by type
|
|
90
|
+
const tags = [{ tagName: '1:Alpha' }, { tagName: '2:Beta' }];
|
|
91
|
+
const characters = FurtrackAPI.getTagsByType(tags, FurtrackAPI.TagTypes.Character);
|
|
92
|
+
// => ['Alpha']
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
MIT License © 2025 blumlaut
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "furtrack-api",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "An inofficial package for accessing the Furtrack API.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"furtrack"
|
|
11
|
+
],
|
|
12
|
+
"author": "blumlaut",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"jest": "^29.7.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* FurtrackAPI provides methods to interact with the Furtrack API, including fetching posts, users, tags, albums, and thumbnails.
|
|
6
|
+
*
|
|
7
|
+
* @class
|
|
8
|
+
* @param {Object} [options] - Configuration options.
|
|
9
|
+
* @param {string} [options.apiKey] - Optional API key for authenticated requests.
|
|
10
|
+
* @param {Object} [options.headers] - Additional headers to include in requests.
|
|
11
|
+
*
|
|
12
|
+
* @property {string} apiKey - The API key used for authentication.
|
|
13
|
+
* @property {string} baseUrl - The base URL for the Furtrack API.
|
|
14
|
+
* @property {Object} agent - HTTPS agent for custom TLS settings.
|
|
15
|
+
* @property {Object} defaultHeaders - Default headers for all requests.
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @property {Object} TagTypes - Enum for tag types.
|
|
19
|
+
* @property {Object} tagTypePrefixes - Mapping of tag prefixes to tag types.
|
|
20
|
+
*
|
|
21
|
+
* @method setApiKey Sets the API key for authentication.
|
|
22
|
+
* @param {string} apiKey - The API key to set.
|
|
23
|
+
*
|
|
24
|
+
* @method setHeaders Sets additional headers for requests.
|
|
25
|
+
* @param {Object} headers - Headers to merge with the default headers.
|
|
26
|
+
*
|
|
27
|
+
* @method fetchJSON Fetches JSON data from a given API path.
|
|
28
|
+
* @param {string} path - The API endpoint path.
|
|
29
|
+
* @param {Object} [options] - Additional fetch options.
|
|
30
|
+
* @returns {Promise<Object>} The parsed JSON response.
|
|
31
|
+
*
|
|
32
|
+
* @method getTag Fetches information about a specific tag.
|
|
33
|
+
* @param {string} tag - The tag to fetch.
|
|
34
|
+
* @returns {Promise<Object>} Tag information.
|
|
35
|
+
*
|
|
36
|
+
* @method getUser Fetches information about a specific user.
|
|
37
|
+
* @param {string} username - The username to fetch.
|
|
38
|
+
* @returns {Promise<Object>} User information.
|
|
39
|
+
*
|
|
40
|
+
* @method getPost Fetches information about a specific post.
|
|
41
|
+
* @param {string|number} postId - The post ID to fetch.
|
|
42
|
+
* @returns {Promise<Object>} Post information.
|
|
43
|
+
*
|
|
44
|
+
* @method getPostsByTag Fetches posts associated with a tag, with pagination.
|
|
45
|
+
* @param {string} tag - The tag to search for.
|
|
46
|
+
* @param {number} [page=0] - The page number for pagination.
|
|
47
|
+
* @returns {Promise<Array>} Array of posts.
|
|
48
|
+
*
|
|
49
|
+
* @method getPostsByUser Fetches posts by a specific user, with pagination.
|
|
50
|
+
* @param {string} username - The username whose posts to fetch.
|
|
51
|
+
* @param {number} [page=0] - The page number for pagination.
|
|
52
|
+
* @returns {Promise<Array>} Array of posts.
|
|
53
|
+
*
|
|
54
|
+
* @method getLikes Fetches posts liked by a user, with pagination.
|
|
55
|
+
* @param {string} username - The username whose liked posts to fetch.
|
|
56
|
+
* @param {number} [page=0] - The page number for pagination.
|
|
57
|
+
* @returns {Promise<Array>} Array of liked posts.
|
|
58
|
+
*
|
|
59
|
+
* @method getThumbnail Constructs the thumbnail URL for a post.
|
|
60
|
+
* @param {string|number} postId - The post ID.
|
|
61
|
+
* @returns {Promise<string>} The thumbnail URL.
|
|
62
|
+
*
|
|
63
|
+
* @method getAlbum Fetches information about a user's album.
|
|
64
|
+
* @param {string} username - The username.
|
|
65
|
+
* @param {string|number} albumId - The album ID.
|
|
66
|
+
* @returns {Promise<Object>} Album information.
|
|
67
|
+
*
|
|
68
|
+
* @method parseTag Parses a tag string into its type and value.
|
|
69
|
+
* @param {string} tagString - The tag string to parse.
|
|
70
|
+
* @returns {Object} An object with `type` and `value` properties.
|
|
71
|
+
*
|
|
72
|
+
* @static
|
|
73
|
+
* @method getTagsByType Filters and extracts tag values by type.
|
|
74
|
+
* @param {Array} tags - Array of tag objects with a `tagName` property.
|
|
75
|
+
* @param {string} type - The tag type to filter by.
|
|
76
|
+
* @returns {Array<string>} Array of tag values matching the type.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
class FurtrackAPI {
|
|
80
|
+
constructor({ apiKey = undefined, headers = {} } = {}) {
|
|
81
|
+
this.apiKey = apiKey;
|
|
82
|
+
this.baseUrl = 'https://solar.furtrack.com';
|
|
83
|
+
this.agent = new https.Agent({
|
|
84
|
+
rejectUnauthorized: false,
|
|
85
|
+
ciphers: 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384',
|
|
86
|
+
honorCipherOrder: true,
|
|
87
|
+
minVersion: 'TLSv1.2',
|
|
88
|
+
maxVersion: 'TLSv1.3'
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
this.defaultHeaders = {
|
|
92
|
+
"User-Agent": `furtrack-api/${require('../package.json').version} (https://github.com/blumlaut/furtrack-api) Mozilla/5.0 (compatible; FurtrackAPI/${require('../package.json').version}`,
|
|
93
|
+
"Accept": "application/json, text/plain, */*",
|
|
94
|
+
"Referer": "https://www.furtrack.com/",
|
|
95
|
+
"Origin": "https://www.furtrack.com",
|
|
96
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
97
|
+
...headers
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (this.apiKey) {
|
|
101
|
+
this.defaultHeaders['Authorization'] = `Bearer ${this.apiKey}`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static TagTypes = {
|
|
106
|
+
Character: 'character',
|
|
107
|
+
Maker: 'maker',
|
|
108
|
+
Photographer: 'photographer',
|
|
109
|
+
Species: 'species',
|
|
110
|
+
Event: 'event',
|
|
111
|
+
General: 'general'
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
static tagTypePrefixes = {
|
|
115
|
+
'1:': this.TagTypes.Character,
|
|
116
|
+
'2:': this.TagTypes.Maker,
|
|
117
|
+
'3:': this.TagTypes.Photographer,
|
|
118
|
+
'5:': this.TagTypes.Event,
|
|
119
|
+
'6': this.TagTypes.Species,
|
|
120
|
+
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
setApiKey(apiKey) {
|
|
124
|
+
this.apiKey = apiKey;
|
|
125
|
+
this.defaultHeaders['Authorization'] = `Bearer ${apiKey}`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setHeaders(headers) {
|
|
129
|
+
this.defaultHeaders = { ...this.defaultHeaders, ...headers };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async fetchJSON(path, options = {}) {
|
|
133
|
+
const url = `${this.baseUrl}${path}`;
|
|
134
|
+
const fetchOptions = {
|
|
135
|
+
method: 'GET',
|
|
136
|
+
agent: this.agent,
|
|
137
|
+
headers: this.defaultHeaders,
|
|
138
|
+
...options
|
|
139
|
+
};
|
|
140
|
+
const res = await fetch(url, fetchOptions);
|
|
141
|
+
if (!res.ok) throw new Error(`HTTP error ${res.status}`);
|
|
142
|
+
return res.json();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getTag(tag) {
|
|
146
|
+
return this.fetchJSON(`/get/index/${encodeURIComponent(tag)}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getUser(username) {
|
|
150
|
+
return this.fetchJSON(`/get/u/${encodeURIComponent(username)}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
getPost(postId) {
|
|
154
|
+
return this.fetchJSON(`/view/post/${encodeURIComponent(postId)}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async getPostsByTag(tag, page = 0) {
|
|
158
|
+
const response = await this.fetchJSON(`/get/tag/${encodeURIComponent(tag)}${page > 0 ? `/${page}` : ''}`);
|
|
159
|
+
return response.posts || [];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async getPostsByUser(username, page = 0) {
|
|
163
|
+
const response = await this.fetchJSON(`/view/album/${encodeURIComponent(username)}/3${page > 0 ? `/${page}` : ''}`);
|
|
164
|
+
return response.posts || [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async getLikes(username, page = 0) {
|
|
168
|
+
const response = await this.fetchJSON(`/view/album/${encodeURIComponent(username)}/o${page > 0 ? `/${page}` : ''}`);
|
|
169
|
+
return response.posts || [];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async getThumbnail(postId) {
|
|
173
|
+
const postData = await this.getPost(postId);
|
|
174
|
+
if (!postData.submitUserId || !postData.id || !postData.metaFingerprint || !postData.metaFiletype) {
|
|
175
|
+
throw new Error('Missing required fields in postData for constructing thumbnail URL');
|
|
176
|
+
}
|
|
177
|
+
return `https://orca2.furtrack.com/gallery/${postData.submitUserId}/${postData.id}-${postData.metaFingerprint}.${postData.metaFiletype}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getAlbum(username, albumId, page = 0) {
|
|
181
|
+
return this.fetchJSON(`/view/album/${encodeURIComponent(username)}/${encodeURIComponent(albumId)}${page > 0 ? `/${page}` : ''}`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
parseTag(tagString) {
|
|
185
|
+
return FurtrackAPI.parseTag(tagString);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static parseTag(tagString) {
|
|
189
|
+
for (const [prefix, type] of Object.entries(this.tagTypePrefixes)) {
|
|
190
|
+
if (tagString.startsWith(prefix)) {
|
|
191
|
+
return { type, value: tagString.slice(prefix.length) };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { type: this.TagTypes.General, value: tagString };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
static getTagsByType(tags, type) {
|
|
199
|
+
return tags
|
|
200
|
+
.map(tag => this.parseTag(tag.tagName))
|
|
201
|
+
.filter(parsed => parsed.type === type)
|
|
202
|
+
.map(parsed => parsed.value);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = FurtrackAPI;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const { test, expect, describe, beforeEach } = require('@jest/globals');
|
|
2
|
+
const FurtrackAPI = require('./index');
|
|
3
|
+
|
|
4
|
+
describe('FurtrackAPI', () => {
|
|
5
|
+
let api;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
api = new FurtrackAPI();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('constructor sets default values', () => {
|
|
12
|
+
expect(api.apiKey).toBeUndefined();
|
|
13
|
+
expect(api.baseUrl).toBe('https://solar.furtrack.com');
|
|
14
|
+
expect(api.defaultHeaders['User-Agent']).toMatch(/furtrack-api/);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('constructor sets apiKey and Authorization header', () => {
|
|
18
|
+
const api2 = new FurtrackAPI({ apiKey: 'abc123' });
|
|
19
|
+
expect(api2.apiKey).toBe('abc123');
|
|
20
|
+
expect(api2.defaultHeaders.Authorization).toBe('Bearer abc123');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('setApiKey updates apiKey and Authorization header', () => {
|
|
24
|
+
api.setApiKey('newkey');
|
|
25
|
+
expect(api.apiKey).toBe('newkey');
|
|
26
|
+
expect(api.defaultHeaders.Authorization).toBe('Bearer newkey');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('setHeaders merges headers', () => {
|
|
30
|
+
api.setHeaders({ 'X-Test': 'foo' });
|
|
31
|
+
expect(api.defaultHeaders['X-Test']).toBe('foo');
|
|
32
|
+
expect(api.defaultHeaders['User-Agent']).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('parseTag', () => {
|
|
36
|
+
test('parses character tag', () => {
|
|
37
|
+
const result = api.parseTag('1:Fluffy');
|
|
38
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Character, value: 'Fluffy' });
|
|
39
|
+
});
|
|
40
|
+
test('parses maker tag', () => {
|
|
41
|
+
const result = api.parseTag('2:MakerName');
|
|
42
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Maker, value: 'MakerName' });
|
|
43
|
+
});
|
|
44
|
+
test('parses photographer tag', () => {
|
|
45
|
+
const result = api.parseTag('3:PhotoGuy');
|
|
46
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Photographer, value: 'PhotoGuy' });
|
|
47
|
+
});
|
|
48
|
+
test('parses event tag', () => {
|
|
49
|
+
const result = api.parseTag('5:SomeEvent');
|
|
50
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Event, value: 'SomeEvent' });
|
|
51
|
+
});
|
|
52
|
+
test('parses species tag', () => {
|
|
53
|
+
const result = api.parseTag('6Wolf');
|
|
54
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Species, value: 'Wolf' });
|
|
55
|
+
});
|
|
56
|
+
test('parses general tag', () => {
|
|
57
|
+
const result = api.parseTag('randomtag');
|
|
58
|
+
expect(result).toEqual({ type: FurtrackAPI.TagTypes.General, value: 'randomtag' });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('getTagsByType', () => {
|
|
63
|
+
test('filters and extracts tag values by type', () => {
|
|
64
|
+
const tags = [
|
|
65
|
+
{ tagName: '1:Alpha' },
|
|
66
|
+
{ tagName: '2:Beta' },
|
|
67
|
+
{ tagName: '1:Gamma' },
|
|
68
|
+
{ tagName: 'random' }
|
|
69
|
+
];
|
|
70
|
+
const result = FurtrackAPI.getTagsByType(tags, FurtrackAPI.TagTypes.Character);
|
|
71
|
+
expect(result).toEqual(['Alpha', 'Gamma']);
|
|
72
|
+
});
|
|
73
|
+
test('returns empty array if no tags match', () => {
|
|
74
|
+
const tags = [{ tagName: '2:Beta' }];
|
|
75
|
+
const result = FurtrackAPI.getTagsByType(tags, FurtrackAPI.TagTypes.Event);
|
|
76
|
+
expect(result).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|