test: remove singular test suites

This commit is contained in:
AB1908 2022-09-17 15:54:41 +05:30
parent 801991213d
commit 89db1a2009
3 changed files with 0 additions and 299 deletions

View file

@ -1,101 +0,0 @@
require('jest-fetch-mock').enableMocks()
let OMDbApiInstance;
beforeEach(() => {
fetchMock.resetMocks();
let OMDbAPI = require("../api/apis/OMDbAPI").OMDbAPI;
let MediaDbPluginMock = {};
MediaDbPluginMock = {
settings: {
OMDbKey: "string"
}
};
OMDbApiInstance = new OMDbAPI(MediaDbPluginMock);
})
test("searchByTitle behavior when given garbage data", async () => {
fetchMock.mockResponseOnce(JSON.stringify({
data: "string"
}))
let res = await OMDbApiInstance.searchByTitle("sample");
expect(res).toEqual([]);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle when fetch returns 401", async () => {
let sampleResponse = {
data: "string"
};
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 401 });
// TODO: Check API name and fix message
// TODO: Externalize string
await expect(async () => await OMDbApiInstance.searchByTitle("sample")).rejects.toThrowError("MDB | Authentication for OMDbAPI failed. Check the API key.");
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle when fetch returns other non-200", async () => {
let sampleResponse = {
data: "string"
};
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 400 });
await expect(async () => await OMDbApiInstance.searchByTitle("sample")).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle with successful request and valid response", async () => {
let response = {
"Search": [
{
"Title": "Guardians of the Galaxy",
"Year": "2014",
"imdbID": "tt2015381",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SX300.jpg"
},
{
"Title": "Guardians of the Galaxy Vol. 2",
"Year": "2017",
"imdbID": "tt3896198",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BNjM0NTc0NzItM2FlYS00YzEwLWE0YmUtNTA2ZWIzODc2OTgxXkEyXkFqcGdeQXVyNTgwNzIyNzg@._V1_SX300.jpg"
},
{
"Title": "Guardians of the Galaxy: Inferno",
"Year": "2017",
"imdbID": "tt7131308",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BZGQ0YzEyNWQtNGJiMi00NTAxLThkNDctNGY2ODkzYWMxZmZkXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SX300.jpg"
},
{
"Title": "LEGO Marvel Super Heroes - Guardians of the Galaxy: The Thanos Threat",
"Year": "2017",
"imdbID": "tt7387224",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BMjhlYzVhNTMtMmFkYy00NDhiLTkyNDgtYzhhMTZiMzM2OTA5XkEyXkFqcGdeQXVyNjI2OTgxNzY@._V1_SX300.jpg"
},
],
"totalResults": "4",
"Response": "True"
}
fetchMock.mockResponse(JSON.stringify(response));
let ret = [];
// import { MovieModel } from '../models/MovieModel';
// const MovieModel = require('../models/MovieModel')
for (const result of response.Search) {
ret.push({
type: 'movie',
title: result.Title,
englishTitle: result.Title,
year: result.Year,
dataSource: 'OMDbAPI',
id: result.imdbID,
});
}
let dt = await OMDbApiInstance.searchByTitle("Jackson");
expect(dt).toEqual(ret);
})

View file

@ -1,103 +0,0 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import fetchMock from 'jest-fetch-mock';
import { OMDbAPI } from '../api/apis/OMDbAPI';
import { MovieModel } from '../models/MovieModel';
import { MediaTypeModel } from '../models/MediaTypeModel';
import MediaDbPlugin from '../main';
import { MediaDbPluginSettings } from 'src/settings/Settings';
enableFetchMocks()
let OMDbApiMock: OMDbAPI;
beforeEach(() => {
fetchMock.resetMocks();
let settingsMock: MediaDbPluginSettings = {
OMDbKey: "string"
} as MediaDbPluginSettings;
let pluginMock: MediaDbPlugin = {} as MediaDbPlugin;
pluginMock.settings = settingsMock;
OMDbApiMock = new OMDbAPI(pluginMock);
})
test("searchByTitle behavior when given garbage data", async () => {
fetchMock.mockResponseOnce(JSON.stringify({
data: "string"
}))
let res = await OMDbApiMock.searchByTitle("sample");
expect(res).toEqual([]);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle when fetch returns 401", async () => {
let sampleResponse = {
data: "string"
};
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 401 });
// TODO: Check API name and fix message
// TODO: Externalize string
await expect(async () => await OMDbApiMock.searchByTitle("sample")).rejects.toThrowError("MDB | Authentication for OMDbAPI failed. Check the API key.");
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle when fetch returns other non-200", async () => {
let sampleResponse = {
data: "string"
};
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 400 });
await expect(async () => await OMDbApiMock.searchByTitle("sample")).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle with successful request and valid response", async () => {
let response = {
"Search": [
{
"Title": "Guardians of the Galaxy",
"Year": "2014",
"imdbID": "tt2015381",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SX300.jpg"
},
{
"Title": "Guardians of the Galaxy Vol. 2",
"Year": "2017",
"imdbID": "tt3896198",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BNjM0NTc0NzItM2FlYS00YzEwLWE0YmUtNTA2ZWIzODc2OTgxXkEyXkFqcGdeQXVyNTgwNzIyNzg@._V1_SX300.jpg"
},
{
"Title": "Guardians of the Galaxy: Inferno",
"Year": "2017",
"imdbID": "tt7131308",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BZGQ0YzEyNWQtNGJiMi00NTAxLThkNDctNGY2ODkzYWMxZmZkXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SX300.jpg"
},
{
"Title": "LEGO Marvel Super Heroes - Guardians of the Galaxy: The Thanos Threat",
"Year": "2017",
"imdbID": "tt7387224",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BMjhlYzVhNTMtMmFkYy00NDhiLTkyNDgtYzhhMTZiMzM2OTA5XkEyXkFqcGdeQXVyNjI2OTgxNzY@._V1_SX300.jpg"
},
],
"totalResults": "4",
"Response": "True"
}
fetchMock.mockResponse(JSON.stringify(response));
let ret: MediaTypeModel[] = [];
for (const result of response.Search) {
ret.push(new MovieModel({
type: 'wiki',
title: result.Title,
englishTitle: result.Title,
year: result.Year,
dataSource: 'OMDbAPI',
id: result.imdbID,
} as unknown as MovieModel));
}
let dt = await OMDbApiMock.searchByTitle("Jackson");
expect(dt).toStrictEqual(ret);
})

View file

@ -1,95 +0,0 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import fetchMock from 'jest-fetch-mock';
import { WikipediaAPI } from '../api/apis/WikipediaAPI';
import { WikiModel } from '../models/WikiModel';
import { MediaTypeModel } from '../models/MediaTypeModel';
enableFetchMocks()
let wikiInstance: WikipediaAPI;
beforeEach(() => {
fetchMock.resetMocks();
wikiInstance = new WikipediaAPI(new (jest.fn())());
})
test("searchByTitle behavior when given garbage data", async () => {
fetchMock.mockResponseOnce(JSON.stringify({
data: "string"
}))
await expect(async () => await wikiInstance.searchByTitle("sample")).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle when fetch returns non-200", async () => {
let sampleResponse = {
data: "string"
};
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 400});
await expect(async () => await wikiInstance.searchByTitle("sample")).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
test("searchByTitle with successful request and valid response", async () => {
let response = {
"batchcomplete": "",
"continue": {
"sroffset": 20,
"continue": "-||"
},
"query": {
"searchinfo": {
"totalhits": 214380
},
"search": [
{
"ns": 0,
"title": "Jackson",
"pageid": 15772,
"size": 3524,
"wordcount": 392,
"timestamp": "2022-06-16T07:22:28Z"
},
{
"ns": 0,
"title": "Michael Jackson",
"pageid": 14995351,
"size": 257103,
"wordcount": 23309,
"timestamp": "2022-06-29T01:15:25Z"
},
{
"ns": 0,
"title": "Andrew Jackson",
"pageid": 1623,
"size": 200137,
"wordcount": 22743,
"timestamp": "2022-07-03T17:53:13Z"
},
{
"ns": 0,
"title": "Janet Jackson",
"pageid": 60070,
"size": 206594,
"wordcount": 21067,
"timestamp": "2022-06-24T19:40:30Z"
}
]
}
};
fetchMock.mockResponse(JSON.stringify(response));
let ret: MediaTypeModel[] = [];
for (const result of response.query.search) {
ret.push(new WikiModel({
type: 'wiki',
title: result.title,
englishTitle: result.title,
year: '',
dataSource: 'Wikipedia API',
id: result.pageid,
} as unknown as WikiModel));
}
let dt = await wikiInstance.searchByTitle("Jackson");
expect(dt).toStrictEqual(ret);
})