diff --git a/src/extractor/DoodStream.test.ts b/src/extractor/DoodStream.test.ts index 25cb4fc..2215308 100644 --- a/src/extractor/DoodStream.test.ts +++ b/src/extractor/DoodStream.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { DoodStream } from './DoodStream'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new DoodStream(new FetcherMock(`${__dirname}/__fixtures__/DoodStream`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('DoodStream', () => { test('dood.to', async () => { diff --git a/src/extractor/Dropload.test.ts b/src/extractor/Dropload.test.ts index fb78de8..4b0843d 100644 --- a/src/extractor/Dropload.test.ts +++ b/src/extractor/Dropload.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { Dropload } from './Dropload'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new Dropload(new FetcherMock(`${__dirname}/__fixtures__/Dropload`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('Dropload', () => { test('dropload.io', async () => { diff --git a/src/extractor/ExternalUrl.test.ts b/src/extractor/ExternalUrl.test.ts index 402f6fd..4ae6201 100644 --- a/src/extractor/ExternalUrl.test.ts +++ b/src/extractor/ExternalUrl.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { ExternalUrl } from './ExternalUrl'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new ExternalUrl(new FetcherMock(`${__dirname}/__fixtures__/ExternalUrl`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { includeExternalUrls: 'on' } }; +const ctx = createTestContext({ includeExternalUrls: 'on' }); describe('ExternalUrl', () => { test('404 - not found', async () => { diff --git a/src/extractor/ExtractorRegistry.test.ts b/src/extractor/ExtractorRegistry.test.ts index 8f9d6bc..999a0bc 100644 --- a/src/extractor/ExtractorRegistry.test.ts +++ b/src/extractor/ExtractorRegistry.test.ts @@ -1,14 +1,15 @@ import winston from 'winston'; import { ExtractorRegistry } from './ExtractorRegistry'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { FetcherMock } from '../utils'; import { createExtractors } from './index'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, createExtractors(new FetcherMock(`${__dirname}/__fixtures__/ExtractorRegistry`))); describe('ExtractorRegistry', () => { - const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; + const ctx = createTestContext(); test('returns error result from extractor', async () => { const urlResult = await extractorRegistry.handle(ctx, new URL('https://some-url.test'), CountryCode.de); diff --git a/src/extractor/Fsst.test.ts b/src/extractor/Fsst.test.ts index 2b5b9c8..fc0450d 100644 --- a/src/extractor/Fsst.test.ts +++ b/src/extractor/Fsst.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { Fsst } from './Fsst'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new Fsst(new FetcherMock(`${__dirname}/__fixtures__/Fsst`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('Fsst', () => { test('Blood & Sinners', async () => { diff --git a/src/extractor/KinoGer.test.ts b/src/extractor/KinoGer.test.ts index a140dba..dcca1fc 100644 --- a/src/extractor/KinoGer.test.ts +++ b/src/extractor/KinoGer.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { KinoGer } from './KinoGer'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new KinoGer(new FetcherMock(`${__dirname}/__fixtures__/KinoGer`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('KinoGer', () => { test('Blood & Sinners', async () => { diff --git a/src/extractor/Soaper.test.ts b/src/extractor/Soaper.test.ts index 05106a8..ba6fee3 100644 --- a/src/extractor/Soaper.test.ts +++ b/src/extractor/Soaper.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { Soaper } from './Soaper'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new Soaper(new FetcherMock(`${__dirname}/__fixtures__/Soaper`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('Soaper', () => { test('Full Metal Jacket', async () => { diff --git a/src/extractor/SuperVideo.test.ts b/src/extractor/SuperVideo.test.ts index 6242cc6..25e4cb7 100644 --- a/src/extractor/SuperVideo.test.ts +++ b/src/extractor/SuperVideo.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { SuperVideo } from './SuperVideo'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new SuperVideo(new FetcherMock(`${__dirname}/__fixtures__/SuperVideo`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('SuperVideo', () => { test('supervideo.cc /e/', async () => { diff --git a/src/extractor/VidSrc.test.ts b/src/extractor/VidSrc.test.ts index d128cc4..2171c51 100644 --- a/src/extractor/VidSrc.test.ts +++ b/src/extractor/VidSrc.test.ts @@ -1,13 +1,14 @@ import winston from 'winston'; import { FetcherMock } from '../utils'; -import { Context, CountryCode } from '../types'; +import { CountryCode } from '../types'; import { ExtractorRegistry } from './ExtractorRegistry'; import { VidSrc } from './VidSrc'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const extractorRegistry = new ExtractorRegistry(logger, [new VidSrc(new FetcherMock(`${__dirname}/__fixtures__/VidSrc`))]); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: {} }; +const ctx = createTestContext(); describe('VidSrc', () => { test('Full Metal Jacket', async () => { diff --git a/src/source/CineHDPlus.test.ts b/src/source/CineHDPlus.test.ts index 48e9939..22dce1b 100644 --- a/src/source/CineHDPlus.test.ts +++ b/src/source/CineHDPlus.test.ts @@ -1,8 +1,8 @@ import { CineHDPlus } from './CineHDPlus'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { es: 'on', mx: 'on' } }; +const ctx = createTestContext({ es: 'on', mx: 'on' }); describe('CineHDPlus', () => { let handler: CineHDPlus; diff --git a/src/source/Cuevana.test.ts b/src/source/Cuevana.test.ts index 7bb7e40..7463203 100644 --- a/src/source/Cuevana.test.ts +++ b/src/source/Cuevana.test.ts @@ -1,8 +1,8 @@ import { Cuevana } from './Cuevana'; import { FetcherMock, TmdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { es: 'on', mx: 'on' } }; +const ctx = createTestContext({ es: 'on', mx: 'on' }); describe('Cuevana', () => { let handler: Cuevana; diff --git a/src/source/Eurostreaming.test.ts b/src/source/Eurostreaming.test.ts index c220ab1..65c06af 100644 --- a/src/source/Eurostreaming.test.ts +++ b/src/source/Eurostreaming.test.ts @@ -1,8 +1,8 @@ import { Eurostreaming } from './Eurostreaming'; import { FetcherMock, TmdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { it: 'on' } }; +const ctx = createTestContext({ it: 'on' }); describe('Eurostreaming', () => { let handler: Eurostreaming; diff --git a/src/source/Frembed.test.ts b/src/source/Frembed.test.ts index 9994de5..ffa509c 100644 --- a/src/source/Frembed.test.ts +++ b/src/source/Frembed.test.ts @@ -1,8 +1,8 @@ import { Frembed } from './Frembed'; import { FetcherMock, ImdbId, TmdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { fr: 'on' } }; +const ctx = createTestContext({ fr: 'on' }); describe('Frembed', () => { let handler: Frembed; diff --git a/src/source/FrenchCloud.test.ts b/src/source/FrenchCloud.test.ts index 30af92a..ee18620 100644 --- a/src/source/FrenchCloud.test.ts +++ b/src/source/FrenchCloud.test.ts @@ -1,8 +1,8 @@ import { FrenchCloud } from './FrenchCloud'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { fr: 'on' } }; +const ctx = createTestContext({ fr: 'on' }); describe('FrenchCloud', () => { let handler: FrenchCloud; diff --git a/src/source/KinoGer.test.ts b/src/source/KinoGer.test.ts index e7283d4..ec76f64 100644 --- a/src/source/KinoGer.test.ts +++ b/src/source/KinoGer.test.ts @@ -1,8 +1,8 @@ import { KinoGer } from './KinoGer'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; +const ctx = createTestContext({ de: 'on' }); describe('KinoGer', () => { let handler: KinoGer; diff --git a/src/source/MeineCloud.test.ts b/src/source/MeineCloud.test.ts index 4e00826..0dac210 100644 --- a/src/source/MeineCloud.test.ts +++ b/src/source/MeineCloud.test.ts @@ -1,8 +1,8 @@ import { MeineCloud } from './MeineCloud'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; +const ctx = createTestContext({ de: 'on' }); describe('MeineCloud', () => { let handler: MeineCloud; diff --git a/src/source/MostraGuarda.test.ts b/src/source/MostraGuarda.test.ts index e852e10..f8d4434 100644 --- a/src/source/MostraGuarda.test.ts +++ b/src/source/MostraGuarda.test.ts @@ -1,8 +1,8 @@ import { MostraGuarda } from './MostraGuarda'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { it: 'on' } }; +const ctx = createTestContext({ it: 'on' }); describe('MostraGuarda', () => { let handler: MostraGuarda; diff --git a/src/source/Soaper.test.ts b/src/source/Soaper.test.ts index b470e25..b5c47ff 100644 --- a/src/source/Soaper.test.ts +++ b/src/source/Soaper.test.ts @@ -1,8 +1,8 @@ import { Soaper } from './Soaper'; import { FetcherMock, ImdbId, TmdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { en: 'on' } }; +const ctx = createTestContext(); describe('Soaper', () => { let handler: Soaper; diff --git a/src/source/StreamKiste.test.ts b/src/source/StreamKiste.test.ts index 614c771..ac55bd9 100644 --- a/src/source/StreamKiste.test.ts +++ b/src/source/StreamKiste.test.ts @@ -1,8 +1,8 @@ import { StreamKiste } from './StreamKiste'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; +const ctx = createTestContext({ de: 'on' }); describe('StreamKiste', () => { let handler: StreamKiste; diff --git a/src/source/VerHdLink.test.ts b/src/source/VerHdLink.test.ts index 16c4784..8e9fc8f 100644 --- a/src/source/VerHdLink.test.ts +++ b/src/source/VerHdLink.test.ts @@ -1,8 +1,8 @@ import { VerHdLink } from './VerHdLink'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { es: 'on', mx: 'on' } }; +const ctx = createTestContext({ es: 'on', mx: 'on' }); describe('VerHdLink', () => { let handler: VerHdLink; diff --git a/src/source/VidSrc.test.ts b/src/source/VidSrc.test.ts index 74afc1d..94dbad0 100644 --- a/src/source/VidSrc.test.ts +++ b/src/source/VidSrc.test.ts @@ -1,8 +1,8 @@ import { VidSrc } from './VidSrc'; import { FetcherMock, ImdbId } from '../utils'; -import { Context } from '../types'; +import { createTestContext } from '../test'; -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { en: 'on' } }; +const ctx = createTestContext(); describe('VidSrc', () => { let handler: VidSrc; diff --git a/src/test/index.ts b/src/test/index.ts new file mode 100644 index 0000000..a4ac9b8 --- /dev/null +++ b/src/test/index.ts @@ -0,0 +1,10 @@ +import { Config, Context } from '../types'; +import { getDefaultConfig } from '../utils'; + +export const createTestContext = (config?: Config): Context => { + return { + id: 'test', + ip: '0.0.0.0', + config: config ?? getDefaultConfig(), + }; +}; diff --git a/src/utils/Fetcher.test.ts b/src/utils/Fetcher.test.ts index 30e9737..636f363 100644 --- a/src/utils/Fetcher.test.ts +++ b/src/utils/Fetcher.test.ts @@ -1,14 +1,14 @@ import winston from 'winston'; import fetchMock from 'fetch-mock'; import { Fetcher } from './Fetcher'; -import { Context } from '../types'; import { BlockedError, HttpError, NotFoundError, QueueIsFullError, TimeoutError, TooManyRequestsError, TooManyTimeoutsError } from '../error'; +import { createTestContext } from '../test'; fetchMock.mockGlobal(); const fetcher = new Fetcher(winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] })); describe('fetch', () => { - const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; + const ctx = createTestContext(); afterEach(() => { fetchMock.clearHistory(); @@ -27,12 +27,12 @@ describe('fetch', () => { headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en', - 'Forwarded': 'for=127.0.0.1', + 'Forwarded': 'for=0.0.0.0', 'Priority': 'u=0', 'User-Agent': 'node', - 'X-Forwarded-For': '127.0.0.1', + 'X-Forwarded-For': '0.0.0.0', 'X-Forwarded-Proto': 'https', - 'X-Real-IP': '127.0.0.1', + 'X-Real-IP': '0.0.0.0', }, }); }); diff --git a/src/utils/StreamResolver.test.ts b/src/utils/StreamResolver.test.ts index 334678f..bd6dc02 100644 --- a/src/utils/StreamResolver.test.ts +++ b/src/utils/StreamResolver.test.ts @@ -3,14 +3,15 @@ import winston from 'winston'; import { createExtractors, Extractor, ExtractorRegistry } from '../extractor'; import { StreamResolver } from './StreamResolver'; import { Source, SourceResult, MeineCloud, MostraGuarda } from '../source'; -import { BlockedReason, Context, CountryCode, UrlResult } from '../types'; +import { BlockedReason, CountryCode, UrlResult } from '../types'; import { BlockedError, HttpError, NotFoundError, QueueIsFullError, TimeoutError, TooManyTimeoutsError, TooManyRequestsError } from '../error'; import { ImdbId } from './id'; import { FetcherMock } from './FetcherMock'; +import { createTestContext } from '../test'; const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); const fetcher = new FetcherMock(`${__dirname}/__fixtures__/StreamResolver`); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on', it: 'on' } }; +const ctx = createTestContext({ de: 'on', it: 'on' }); const meineCloud = new MeineCloud(fetcher); const mostraGuarda = new MostraGuarda(fetcher); diff --git a/src/utils/__snapshots__/StreamResolver.test.ts.snap b/src/utils/__snapshots__/StreamResolver.test.ts.snap index 41f2aba..3707ff7 100644 --- a/src/utils/__snapshots__/StreamResolver.test.ts.snap +++ b/src/utils/__snapshots__/StreamResolver.test.ts.snap @@ -35,7 +35,7 @@ exports[`resolve adds error info 1`] = ` "behaviorHints": {}, "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -❌ Request failed. Request-id: id.", +❌ Request failed. Request-id: test.", "ytId": "E4WlUXrJgy4", }, { @@ -56,7 +56,7 @@ exports[`resolve adds error info 1`] = ` "behaviorHints": {}, "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -❌ Request failed with status 500 (Internal Server Error). Request-id: id.", +❌ Request failed with status 500 (Internal Server Error). Request-id: test.", "ytId": "E4WlUXrJgy4", }, ], @@ -99,7 +99,7 @@ exports[`resolve adds error info 2`] = ` "externalUrl": "https://example2.com/", "name": "WebStreamr 🇩🇪 ⚠️ external", "title": "🔗 hoster.com -❌ Request failed. Request-id: id.", +❌ Request failed. Request-id: test.", }, { "behaviorHints": {}, @@ -120,7 +120,7 @@ exports[`resolve adds error info 2`] = ` "externalUrl": "https://example4.com/", "name": "WebStreamr 🇩🇪 ⚠️ external", "title": "🔗 hoster.com -❌ Request failed with status 500 (Internal Server Error). Request-id: id.", +❌ Request failed with status 500 (Internal Server Error). Request-id: test.", }, ], } @@ -333,7 +333,7 @@ exports[`resolve returns source errors as stream 1`] = ` { "name": "WebStreamr", "title": "🔗 MeineCloud -❌ Request failed. Request-id: id.", +❌ Request failed. Request-id: test.", "ytId": "E4WlUXrJgy4", }, ], diff --git a/src/utils/tmdb.test.ts b/src/utils/tmdb.test.ts index c1f5974..2e00575 100644 --- a/src/utils/tmdb.test.ts +++ b/src/utils/tmdb.test.ts @@ -1,10 +1,10 @@ import { getImdbIdFromTmdbId, getTmdbIdFromImdbId } from './tmdb'; -import { Context } from '../types'; import { ImdbId, TmdbId } from './id'; import { FetcherMock } from './FetcherMock'; +import { createTestContext } from '../test'; const fetcher = new FetcherMock(`${__dirname}/__fixtures__/tmdb`); -const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; +const ctx = createTestContext(); describe('getTmdbIdFromImdbId', () => { test('series', async () => { diff --git a/tsconfig.json b/tsconfig.json index 3f0120d..cd4b981 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,5 +25,5 @@ "useUnknownInCatchVariables": true }, "include": ["src/**/*"], - "exclude": ["node_modules", "**/*.test.ts"] + "exclude": ["node_modules", "src/test", "**/*.test.ts"] }