Clean-up after merge
This commit is contained in:
parent
391915eb09
commit
da16b2af6a
15 changed files with 177 additions and 171 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "obsidian-media-db-plugin",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-media-db-plugin",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"ts-node": "^10.8.1",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-media-db-plugin",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"description": "A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
}
|
||||
|
||||
const data = fetchData.text;
|
||||
const response = new window.DOMParser().parseFromString(data, "text/xml")
|
||||
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
||||
|
||||
debugLog(response);
|
||||
|
||||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const boardgame of Array.from(response.querySelectorAll("boardgame"))) {
|
||||
const id = boardgame.attributes.getNamedItem("objectid")!.value;
|
||||
const title = boardgame.querySelector("name")!.textContent!;
|
||||
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
|
||||
for (const boardgame of Array.from(response.querySelectorAll('boardgame'))) {
|
||||
const id = boardgame.attributes.getNamedItem('objectid')!.value;
|
||||
const title = boardgame.querySelector('name')!.textContent!;
|
||||
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
||||
|
||||
ret.push(new BoardGameModel({
|
||||
dataSource: this.apiName,
|
||||
|
|
@ -68,21 +68,21 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
}
|
||||
|
||||
const data = fetchData.text;
|
||||
const response = new window.DOMParser().parseFromString(data, "text/xml")
|
||||
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
||||
debugLog(response);
|
||||
|
||||
const boardgame = response.querySelector("boardgame")!;
|
||||
const title = boardgame.querySelector("name")!.textContent!;
|
||||
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
|
||||
const image = boardgame.querySelector("image")?.textContent ?? undefined;
|
||||
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average")?.textContent ?? "");
|
||||
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n!.textContent!);
|
||||
const boardgame = response.querySelector('boardgame')!;
|
||||
const title = boardgame.querySelector('name')!.textContent!;
|
||||
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
||||
const image = boardgame.querySelector('image')?.textContent ?? undefined;
|
||||
const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '');
|
||||
const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!);
|
||||
|
||||
const model = new BoardGameModel({
|
||||
type: MediaType.BoardGame,
|
||||
title,
|
||||
englishTitle: title,
|
||||
year: year === "0" ? "" : year,
|
||||
year: year === '0' ? '' : year,
|
||||
dataSource: this.apiName,
|
||||
url: `https://boardgamegeek.com/boardgame/${id}`,
|
||||
id,
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
const erroredFiles: { filePath: string, error: string }[] = [];
|
||||
let canceled: boolean = false;
|
||||
|
||||
const {selectedAPI, titleFieldName, appendContent} = await new Promise<{selectedAPI: string, titleFieldName: string, appendContent: boolean}>((resolve, reject) => {
|
||||
const {selectedAPI, titleFieldName, appendContent} = await new Promise<{ selectedAPI: string, titleFieldName: string, appendContent: boolean }>((resolve, reject) => {
|
||||
new MediaDbFolderImportModal(this.app, this, ((selectedAPI: string, titleFieldName: string, appendContent: boolean) => {
|
||||
resolve({selectedAPI, titleFieldName, appendContent});
|
||||
})).open();
|
||||
|
|
@ -402,7 +402,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve(res)
|
||||
resolve(res);
|
||||
}).open();
|
||||
});
|
||||
}
|
||||
|
|
@ -413,7 +413,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve(res)
|
||||
resolve(res);
|
||||
}).open();
|
||||
});
|
||||
}
|
||||
|
|
@ -426,7 +426,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
}
|
||||
resolve(res);
|
||||
}, () => {
|
||||
resolve([])
|
||||
resolve([]);
|
||||
}).open();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
isBusy: boolean;
|
||||
plugin: MediaDbPlugin;
|
||||
searchBtn: ButtonComponent;
|
||||
selectedApis: {name: string, selected: boolean}[];
|
||||
onSubmit: (res: {query: string, apis: string[]}, err?: Error) => void;
|
||||
selectedApis: { name: string, selected: boolean }[];
|
||||
onSubmit: (res: { query: string, apis: string[] }, err?: Error) => void;
|
||||
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (res: {query: string, apis: string[]}, err?: Error) => void) {
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (res: { query: string, apis: string[] }, err?: Error) => void) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.onSubmit = onSubmit;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
plugin: MediaDbPlugin;
|
||||
searchBtn: ButtonComponent;
|
||||
selectedApi: string;
|
||||
onSubmit: (res: {query: string, api: string}, err?: Error) => void;
|
||||
onSubmit: (res: { query: string, api: string }, err?: Error) => void;
|
||||
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (res: {query: string, api: string}, err?: Error) => void) {
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (res: { query: string, api: string }, err?: Error) => void) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.onSubmit = onSubmit;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ export class MusicReleaseModel extends MediaTypeModel {
|
|||
|
||||
getSummary(): string {
|
||||
var summary = this.title + ' (' + this.year + ')';
|
||||
if(this.artists.length > 0)
|
||||
summary += ' - ' + this.artists.join(', ')
|
||||
if (this.artists.length > 0)
|
||||
summary += ' - ' + this.artists.join(', ');
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,77 +1,77 @@
|
|||
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
|
||||
import { MediaDbPluginSettings } from 'src/settings/Settings';
|
||||
import { LocGovAPI } from '../api/apis/LocGovAPI';
|
||||
import { MALAPI } from '../api/apis/MALAPI';
|
||||
import { MusicBrainzAPI } from '../api/apis/MusicBrainzAPI';
|
||||
import { OMDbAPI } from '../api/apis/OMDbAPI';
|
||||
import { SteamAPI } from '../api/apis/SteamAPI';
|
||||
import { WikipediaAPI } from '../api/apis/WikipediaAPI';
|
||||
import fetchMock, {enableFetchMocks} from 'jest-fetch-mock';
|
||||
import {MediaDbPluginSettings} from 'src/settings/Settings';
|
||||
import {LocGovAPI} from '../api/apis/LocGovAPI';
|
||||
import {MALAPI} from '../api/apis/MALAPI';
|
||||
import {MusicBrainzAPI} from '../api/apis/MusicBrainzAPI';
|
||||
import {OMDbAPI} from '../api/apis/OMDbAPI';
|
||||
import {SteamAPI} from '../api/apis/SteamAPI';
|
||||
import {WikipediaAPI} from '../api/apis/WikipediaAPI';
|
||||
import MediaDbPlugin from '../main';
|
||||
import { setMALResponseMock, setMusicBrainzResponseMock, setOMDbResponseMock, setSteamResponseMock, setWikipediaResponseMock } from "./mockHelpers";
|
||||
import MALMockMovie from "./ResponseMocks/MALMockMovie.json";
|
||||
import MusicBrainzResponseMock from "./ResponseMocks/MusicBrainzMockResponse.json";
|
||||
import OMDBMockMovie from "./ResponseMocks/OMDBMockResponse.json";
|
||||
import SteamAPIResponseMock from "./ResponseMocks/SteamAPIMockResponse.json";
|
||||
import WikipediaMockResponse from "./ResponseMocks/WikipediaMockResponse.json";
|
||||
import {setMALResponseMock, setMusicBrainzResponseMock, setOMDbResponseMock, setSteamResponseMock, setWikipediaResponseMock} from './mockHelpers';
|
||||
import MALMockMovie from './ResponseMocks/MALMockMovie.json';
|
||||
import MusicBrainzResponseMock from './ResponseMocks/MusicBrainzMockResponse.json';
|
||||
import OMDBMockMovie from './ResponseMocks/OMDBMockResponse.json';
|
||||
import SteamAPIResponseMock from './ResponseMocks/SteamAPIMockResponse.json';
|
||||
import WikipediaMockResponse from './ResponseMocks/WikipediaMockResponse.json';
|
||||
|
||||
enableFetchMocks();
|
||||
export let apiMock: OMDbAPI | MALAPI | LocGovAPI | MusicBrainzAPI | SteamAPI | WikipediaAPI;
|
||||
|
||||
describe.each(
|
||||
[
|
||||
{ name: OMDbAPI },
|
||||
{ name: MALAPI },
|
||||
{ name: LocGovAPI },
|
||||
{ name: MusicBrainzAPI },
|
||||
{ name: SteamAPI },
|
||||
{ name: WikipediaAPI }
|
||||
]
|
||||
)('$name.name', ({ name: parameterizedApi }) => {
|
||||
{name: OMDbAPI},
|
||||
{name: MALAPI},
|
||||
{name: LocGovAPI},
|
||||
{name: MusicBrainzAPI},
|
||||
{name: SteamAPI},
|
||||
{name: WikipediaAPI},
|
||||
],
|
||||
)('$name.name', ({name: parameterizedApi}) => {
|
||||
beforeAll(() => {
|
||||
let settingsMock: MediaDbPluginSettings = {} as MediaDbPluginSettings;
|
||||
let pluginMock = {} as MediaDbPlugin;
|
||||
pluginMock.settings = settingsMock;
|
||||
// TODO: add fake API key?
|
||||
apiMock = new parameterizedApi(pluginMock);
|
||||
})
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.resetMocks();
|
||||
})
|
||||
});
|
||||
|
||||
test("searchByTitle behavior when API returns garbage data", async () => {
|
||||
test('searchByTitle behavior when API returns garbage data', async () => {
|
||||
const garbageResponse = JSON.stringify({
|
||||
data: "string"
|
||||
data: 'string',
|
||||
});
|
||||
fetchMock.mockResponseOnce(garbageResponse)
|
||||
await expect(apiMock.searchByTitle("sample")).resolves.toEqual([]);
|
||||
fetchMock.mockResponseOnce(garbageResponse);
|
||||
await expect(apiMock.searchByTitle('sample')).resolves.toEqual([]);
|
||||
// }
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("searchByTitle behavior when requestUrl/fetch returns 401", async () => {
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 401', async () => {
|
||||
let sampleResponse = {
|
||||
data: "string"
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 401 });
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 401});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle("sample")).rejects.toThrow(`MDB | Received status code ${401} from an API.`);
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${401} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("searchByTitle behavior when requestUrl/fetch returns 403", async () => {
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 403', async () => {
|
||||
let sampleResponse = {
|
||||
data: "string"
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 403 });
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 403});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string/import?
|
||||
await expect(apiMock.searchByTitle("sample")).rejects.toThrow(`MDB | Received status code ${403} from an API.`);
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${403} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("searchByTitle behavior when requestUrl/fetch returns 200", async () => {
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 200', async () => {
|
||||
let sampleResponse;
|
||||
let ret;
|
||||
switch (parameterizedApi) {
|
||||
|
|
@ -101,10 +101,10 @@ describe.each(
|
|||
default:
|
||||
throw Error();
|
||||
}
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 200 });
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 200});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle("Hooking Season Playtest")).resolves.toEqual(ret);
|
||||
await expect(apiMock.searchByTitle('Hooking Season Playtest')).resolves.toEqual(ret);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
{
|
||||
"release-groups": [
|
||||
{
|
||||
"id": "9cf08bf9-1948-4087-abe1-783210ea1fae",
|
||||
"primary-type-id": "f529b476-6e62-324f-b0aa-1f3e33d313fc",
|
||||
"title": "Halo Halo",
|
||||
"first-release-date": "2013-07-08",
|
||||
"primary-type": "Album",
|
||||
"artist-credit": [
|
||||
{
|
||||
"name": "Halo Halo",
|
||||
"artist": {
|
||||
"name": "Halo Halo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"releases": [
|
||||
{
|
||||
"id": "58dd1d57-2201-472e-9e36-5d497dcedb6f",
|
||||
"title": "Halo Halo"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
"release-groups": [
|
||||
{
|
||||
"id": "9cf08bf9-1948-4087-abe1-783210ea1fae",
|
||||
"primary-type-id": "f529b476-6e62-324f-b0aa-1f3e33d313fc",
|
||||
"title": "Halo Halo",
|
||||
"first-release-date": "2013-07-08",
|
||||
"primary-type": "Album",
|
||||
"artist-credit": [
|
||||
{
|
||||
"name": "Halo Halo",
|
||||
"artist": {
|
||||
"name": "Halo Halo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"releases": [
|
||||
{
|
||||
"id": "58dd1d57-2201-472e-9e36-5d497dcedb6f",
|
||||
"title": "Halo Halo"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"Type": "movie",
|
||||
"Poster": "https://m.media-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SX300.jpg"
|
||||
}
|
||||
],
|
||||
],
|
||||
"totalResults": "1",
|
||||
"Response": "True"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"applist": {
|
||||
"apps": [
|
||||
{
|
||||
"appid": 2076590,
|
||||
"name": "Hooking Season Playtest"
|
||||
},
|
||||
{
|
||||
"appid": 2076600,
|
||||
"name": "MonsterTamer"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"applist": {
|
||||
"apps": [
|
||||
{
|
||||
"appid": 2076590,
|
||||
"name": "Hooking Season Playtest"
|
||||
},
|
||||
{
|
||||
"appid": 2076600,
|
||||
"name": "MonsterTamer"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
{
|
||||
"query": {
|
||||
"searchinfo": {
|
||||
"totalhits": 1199001,
|
||||
"suggestion": "book",
|
||||
"suggestionsnippet": "book"
|
||||
},
|
||||
"search": [
|
||||
{
|
||||
"ns": 0,
|
||||
"title": "Book",
|
||||
"pageid": 3778,
|
||||
"size": 68829,
|
||||
"wordcount": 8821,
|
||||
"snippet": "called <span class=\"searchmatch\">books</span> or chapters or parts, are parts. The intellectual content in a physical book need not be a composition, nor even be called a book. <span class=\"searchmatch\">Books</span> can",
|
||||
"timestamp": "2022-08-19T19:13:56Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"query": {
|
||||
"searchinfo": {
|
||||
"totalhits": 1199001,
|
||||
"suggestion": "book",
|
||||
"suggestionsnippet": "book"
|
||||
},
|
||||
"search": [
|
||||
{
|
||||
"ns": 0,
|
||||
"title": "Book",
|
||||
"pageid": 3778,
|
||||
"size": 68829,
|
||||
"wordcount": 8821,
|
||||
"snippet": "called <span class=\"searchmatch\">books</span> or chapters or parts, are parts. The intellectual content in a physical book need not be a composition, nor even be called a book. <span class=\"searchmatch\">Books</span> can",
|
||||
"timestamp": "2022-08-19T19:13:56Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { GameModel } from "../models/GameModel";
|
||||
import { MovieModel } from '../models/MovieModel';
|
||||
import { MusicReleaseModel } from "../models/MusicReleaseModel";
|
||||
import { WikiModel } from '../models/WikiModel';
|
||||
import { MediaType } from "../utils/MediaType";
|
||||
import { apiMock } from "./ParameterizedAPI.test";
|
||||
import MALMockMovie from "./ResponseMocks/MALMockMovie.json";
|
||||
import MusicBrainzResponseMock from "./ResponseMocks/MusicBrainzMockResponse.json";
|
||||
import OMDBMockMovie from "./ResponseMocks/OMDBMockResponse.json";
|
||||
import SteamAPIResponseMock from "./ResponseMocks/SteamAPIMockResponse.json";
|
||||
import WikipediaMockResponse from "./ResponseMocks/WikipediaMockResponse.json";
|
||||
import {GameModel} from '../models/GameModel';
|
||||
import {MovieModel} from '../models/MovieModel';
|
||||
import {MusicReleaseModel} from '../models/MusicReleaseModel';
|
||||
import {WikiModel} from '../models/WikiModel';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
import {apiMock} from './ParameterizedAPI.test';
|
||||
import MALMockMovie from './ResponseMocks/MALMockMovie.json';
|
||||
import MusicBrainzResponseMock from './ResponseMocks/MusicBrainzMockResponse.json';
|
||||
import OMDBMockMovie from './ResponseMocks/OMDBMockResponse.json';
|
||||
import SteamAPIResponseMock from './ResponseMocks/SteamAPIMockResponse.json';
|
||||
import WikipediaMockResponse from './ResponseMocks/WikipediaMockResponse.json';
|
||||
|
||||
export function setWikipediaResponseMock() {
|
||||
let ret = [];
|
||||
|
|
@ -55,33 +55,31 @@ export function setMALResponseMock() {
|
|||
export function setSteamResponseMock() {
|
||||
let ret = [];
|
||||
let steamResponse = SteamAPIResponseMock.applist.apps[0];
|
||||
ret.push(
|
||||
new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: steamResponse.name,
|
||||
englishTitle: steamResponse.name,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: steamResponse.appid,
|
||||
})
|
||||
)
|
||||
ret.push(new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: steamResponse.name,
|
||||
englishTitle: steamResponse.name,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: steamResponse.appid,
|
||||
}));
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function setMusicBrainzResponseMock() {
|
||||
let ret = [];
|
||||
let result = MusicBrainzResponseMock["release-groups"][0];
|
||||
ret.push(new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: (new Date(result['first-release-date'])).getFullYear().toString(),
|
||||
dataSource: apiMock.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
let result = MusicBrainzResponseMock['release-groups'][0];
|
||||
ret.push(new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: (new Date(result['first-release-date'])).getFullYear().toString(),
|
||||
dataSource: apiMock.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel));
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel));
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,29 @@
|
|||
import { wrapAround, containsOnlyLettersAndUnderscores, replaceIllegalFileNameCharactersInString} from '../utils/Utils';
|
||||
import {containsOnlyLettersAndUnderscores, replaceIllegalFileNameCharactersInString, wrapAround} from '../utils/Utils';
|
||||
|
||||
test('If wrapAround wraps correctly', () => {
|
||||
expect(wrapAround(100,5)).toBe(0);
|
||||
expect(wrapAround(100,7)).toBe(2);
|
||||
expect(wrapAround(100, 5)).toBe(0);
|
||||
expect(wrapAround(100, 7)).toBe(2);
|
||||
});
|
||||
|
||||
test('If wrapAround errors out when dividing by zero', () => {
|
||||
expect(wrapAround(100,0)).toThrow();
|
||||
expect(wrapAround(100, 0)).toThrow();
|
||||
});
|
||||
|
||||
test('If wrapAround errors out when size is negative', () => {
|
||||
expect(wrapAround(100, -5)).toThrow();
|
||||
});
|
||||
|
||||
test('Letter and underscore string validity', () => {
|
||||
expect(containsOnlyLettersAndUnderscores("asdkfj_")).toBe(true);
|
||||
expect(containsOnlyLettersAndUnderscores("asdkfj0")).toBe(false);
|
||||
expect(containsOnlyLettersAndUnderscores('asdkfj_')).toBe(true);
|
||||
expect(containsOnlyLettersAndUnderscores('asdkfj0')).toBe(false);
|
||||
});
|
||||
|
||||
test('Letter and underscore unicode char test', () =>{
|
||||
expect(containsOnlyLettersAndUnderscores("asdkaÈj")).toBe(true);
|
||||
expect(containsOnlyLettersAndUnderscores("asdkaÈj0")).toBe(false);
|
||||
// since this is used to check if a string is a valid name for an object property, unicode characters shouldn't be allowed, thus the name of the function is misleading
|
||||
test('Letter and underscore unicode char test', () => {
|
||||
expect(containsOnlyLettersAndUnderscores('asdkaÈj')).toBe(true);
|
||||
expect(containsOnlyLettersAndUnderscores('asdkaÈj0')).toBe(false);
|
||||
});
|
||||
|
||||
test('Valid filename test', ()=>{
|
||||
expect(replaceIllegalFileNameCharactersInString("what?is\\this:")).toBe("whatisthis -");
|
||||
})
|
||||
test('Valid filename test', () => {
|
||||
expect(replaceIllegalFileNameCharactersInString('what?is\\this:')).toBe('whatisthis -');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ export const mediaDbVersion: string = '0.3.2';
|
|||
export const debug: boolean = true;
|
||||
|
||||
export function wrapAround(value: number, size: number): number {
|
||||
return ((value % size) + size) % size;
|
||||
if (size <= 0) {
|
||||
throw Error('size may not be zero or negative');
|
||||
}
|
||||
return mod(value, size);
|
||||
}
|
||||
|
||||
export function debugLog(o: any): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue