unit tests for provider checks, provider listings, utils and provider meta

This commit is contained in:
mrjvs
2023-09-05 20:57:10 +02:00
parent 391432c1ba
commit bcf312d1b3
11 changed files with 476 additions and 61 deletions

View 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,
});
});
});