mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
unit tests for provider checks, provider listings, utils and provider meta
This commit is contained in:
121
src/__test__/runner/list.test.ts
Normal file
121
src/__test__/runner/list.test.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
import { mockEmbeds, mockSources } from '@/__test__/providerTests';
|
||||
import { makeProviders } from '@/main/builder';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const mocks = await vi.hoisted(async () => (await import('@/__test__/providerTests')).makeProviderMocks());
|
||||
vi.mock('@/providers/all', () => mocks);
|
||||
|
||||
describe('ProviderControls.listSources()', () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return the source with movie type', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceYMovie]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.listSources()).toEqual([
|
||||
{
|
||||
type: 'source',
|
||||
id: 'y',
|
||||
rank: mockSources.fullSourceYMovie.rank,
|
||||
name: 'Y',
|
||||
mediaTypes: ['movie'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the source with show type', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceYShow]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.listSources()).toEqual([
|
||||
{
|
||||
type: 'source',
|
||||
id: 'y',
|
||||
rank: mockSources.fullSourceYShow.rank,
|
||||
name: 'Y',
|
||||
mediaTypes: ['show'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the source with both types', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceZBoth]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.listSources()).toEqual([
|
||||
{
|
||||
type: 'source',
|
||||
id: 'z',
|
||||
rank: mockSources.fullSourceZBoth.rank,
|
||||
name: 'Z',
|
||||
mediaTypes: ['movie', 'show'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the sources in correct order', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceYMovie, mockSources.fullSourceZBoth]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p1 = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
const l1 = p1.listSources();
|
||||
expect(l1.map((v) => v.id).join(',')).toEqual('z,y');
|
||||
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceZBoth, mockSources.fullSourceYMovie]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p2 = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
const l2 = p2.listSources();
|
||||
expect(l2.map((v) => v.id).join(',')).toEqual('z,y');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ProviderControls.getAllEmbedMetaSorted()', () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return the correct embed format', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.fullEmbedX]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.listEmbeds()).toEqual([
|
||||
{
|
||||
type: 'embed',
|
||||
id: 'x',
|
||||
rank: mockEmbeds.fullEmbedX.rank,
|
||||
name: 'X',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the embeds in correct order', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.fullEmbedX, mockEmbeds.fullEmbedZ]);
|
||||
const p1 = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
const l1 = p1.listEmbeds();
|
||||
expect(l1.map((v) => v.id).join(',')).toEqual('z,x');
|
||||
|
||||
mocks.gatherAllSources.mockReturnValue([]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.fullEmbedZ, mockEmbeds.fullEmbedX]);
|
||||
const p2 = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
const l2 = p2.listEmbeds();
|
||||
expect(l2.map((v) => v.id).join(',')).toEqual('z,x');
|
||||
});
|
||||
});
|
50
src/__test__/runner/meta.test.ts
Normal file
50
src/__test__/runner/meta.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { mockEmbeds, mockSources } from '@/__test__/providerTests';
|
||||
import { makeProviders } from '@/main/builder';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const mocks = await vi.hoisted(async () => (await import('@/__test__/providerTests')).makeProviderMocks());
|
||||
vi.mock('@/providers/all', () => mocks);
|
||||
|
||||
describe('ProviderControls.getMetadata()', () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return null if not found', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.getMetadata(':)')).toEqual(null);
|
||||
});
|
||||
|
||||
it('should return correct source meta', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([mockSources.fullSourceZBoth]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.getMetadata(mockSources.fullSourceZBoth.id)).toEqual({
|
||||
type: 'source',
|
||||
id: 'z',
|
||||
name: 'Z',
|
||||
rank: mockSources.fullSourceZBoth.rank,
|
||||
mediaTypes: ['movie', 'show'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return correct embed meta', () => {
|
||||
mocks.gatherAllSources.mockReturnValue([]);
|
||||
mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.fullEmbedX]);
|
||||
const p = makeProviders({
|
||||
fetcher: null as any,
|
||||
});
|
||||
expect(p.getMetadata(mockEmbeds.fullEmbedX.id)).toEqual({
|
||||
type: 'embed',
|
||||
id: 'x',
|
||||
name: 'X',
|
||||
rank: mockEmbeds.fullEmbedX.rank,
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user