diff --git a/src/__test__/providers/embeds.test.ts b/src/__test__/providers/embeds.test.ts new file mode 100644 index 0000000..5775a91 --- /dev/null +++ b/src/__test__/providers/embeds.test.ts @@ -0,0 +1,17 @@ +import { febboxMp4Scraper } from "@/providers/embeds/febbox/mp4"; +import { testEmbed } from "./providerUtils"; +import dotenv from 'dotenv'; + +dotenv.config(); + +testEmbed({ + embed: febboxMp4Scraper, + testUrls: [ + '/show/16448/1/1', + '/movie/27769//' + ], + types: ['standard', 'proxied'], + expect: { + streams: 1, + } +}) diff --git a/src/__test__/providers/providerUtils.ts b/src/__test__/providers/providerUtils.ts index b9b2bc8..4675f86 100644 --- a/src/__test__/providers/providerUtils.ts +++ b/src/__test__/providers/providerUtils.ts @@ -1,15 +1,15 @@ import { ScrapeMedia } from "@/entrypoint/utils/media"; -import { Sourcerer } from "@/providers/base"; +import { Embed, Sourcerer } from "@/providers/base"; import { buildProviders } from "@/entrypoint/builder"; import { describe, expect, it } from "vitest"; import { makeStandardFetcher } from "@/fetchers/standardFetch"; import { ProviderControls } from "@/entrypoint/controls"; import { NotFoundError } from "@/utils/errors"; import { targets } from "@/entrypoint/utils/targets"; -import { getAllEmbedMetaSorted } from "@/entrypoint/utils/meta"; import { getBuiltinEmbeds } from "@/entrypoint/providers"; +import { makeSimpleProxyFetcher } from "@/fetchers/simpleProxy"; -export type TestTypes = 'standard' | 'ip:standard'; +export type TestTypes = 'standard' | 'ip:standard' | 'proxied'; export interface TestSourceOptions { source: Sourcerer; @@ -24,14 +24,28 @@ export interface TestSourceOptions { } } -// TODO add proxy support +export interface TestEmbedOptions { + embed: Embed; + testUrls: string[]; + types: TestTypes[]; + debug?: boolean; + expect: { + streams?: number; + error?: boolean; + } +} function makeBaseProviders() { + const builder = makeBaseEmbedProviders(); + const embeds = getBuiltinEmbeds(); + embeds.forEach(embed => builder.addEmbed(embed)); + return builder; +} + +function makeBaseEmbedProviders() { const builder = buildProviders() .setTarget(targets.ANY) .setFetcher(makeStandardFetcher(fetch)); - const embeds = getBuiltinEmbeds(); - embeds.forEach(embed => builder.addEmbed(embed)); return builder; } @@ -83,6 +97,74 @@ export function testSource(ops: TestSourceOptions) { await runTest(providers); }) } + + if (ops.types.includes('proxied')) { + it(`Should pass test ${i} - proxied`, async () => { + if (!process.env.MOVIE_WEB_PROXY_URL) + throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); + const providers = makeBaseProviders() + .addSource(ops.source) + .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) + .build(); + await runTest(providers); + }) + } + }) + }) +} + +export function testEmbed(ops: TestEmbedOptions) { + if (ops.testUrls.length === 0) throw new Error("Test urls must have at least one url"); + describe(`embed:${ops.embed.id}`, () => { + ops.testUrls.forEach((test, i) => { + async function runTest(providers: ProviderControls) { + let hasError = false; + let streamCount = 0; + try { + const result = await providers.runEmbedScraper({ + id: ops.embed.id, + url: test, + }) + if (ops.debug) console.log(result); + streamCount = (result.stream ?? []).length; + } catch (err) { + if (ops.debug) console.log(err); + hasError = true; + } + expect(ops.expect.error ?? false).toBe(hasError); + expect(ops.expect.streams ?? 0).toBe(streamCount); + } + + if (ops.types.includes('standard')) { + it(`Should pass test ${i} - standard`, async () => { + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .build(); + await runTest(providers); + }) + } + + if (ops.types.includes('ip:standard')) { + it(`Should pass test ${i} - standard:ip`, async () => { + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .enableConsistentIpForRequests() + .build(); + await runTest(providers); + }) + } + + if (ops.types.includes('proxied')) { + it(`Should pass test ${i} - proxied`, async () => { + if (!process.env.MOVIE_WEB_PROXY_URL) + throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) + .build(); + await runTest(providers); + }) + } }) }) } diff --git a/src/__test__/providers/providers.test.ts b/src/__test__/providers/providers.test.ts index 6114f37..0f29dc1 100644 --- a/src/__test__/providers/providers.test.ts +++ b/src/__test__/providers/providers.test.ts @@ -2,8 +2,9 @@ import { testSource } from "./providerUtils"; import { lookmovieScraper } from "@/providers/sources/lookmovie"; import { testMedia } from "./testMedia"; import { showboxScraper } from "@/providers/sources/showbox"; +import dotenv from 'dotenv'; -// TODO add embed testing +dotenv.config(); testSource({ source: lookmovieScraper, @@ -17,7 +18,7 @@ testSource({ testSource({ source: showboxScraper, testSuite: [testMedia.arcane, testMedia.hamilton], - types: ['standard'], + types: ['standard', 'proxied'], expect: { embeds: 1, }