|
| 1 | +import { fetchOmdbData, getSeriesDetail } from '../helpers/appHelper'; |
| 2 | +import History from '../models/History'; |
| 3 | + |
| 4 | +jest.mock('../helpers/appHelper', () => { |
| 5 | + const actual = jest.requireActual('../helpers/appHelper'); |
| 6 | + return { |
| 7 | + ...actual, |
| 8 | + fetchOmdbData: jest.fn(), |
| 9 | + getSeriesDetail: jest.fn(), |
| 10 | + }; |
| 11 | +}); |
| 12 | + |
| 13 | +jest.mock('../models/History', () => ({ |
| 14 | + __esModule: true, |
| 15 | + default: { |
| 16 | + findOneAndUpdate: jest.fn(), |
| 17 | + }, |
| 18 | +})); |
| 19 | + |
| 20 | +describe('controllers/appController with MULTI_DOMAIN', () => { |
| 21 | + let appController: any; |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + jest.resetModules(); |
| 25 | + jest.doMock('../config/app', () => ({ |
| 26 | + VIDSRC_DOMAIN: 'domain', |
| 27 | + MULTI_DOMAIN: 'multi', |
| 28 | + APP_URL: 'http://app', |
| 29 | + APP_NAME: 'name', |
| 30 | + APP_SUBTITLE: '', |
| 31 | + APP_DESCRIPTION: '', |
| 32 | + })); |
| 33 | + appController = require('./appController').default; |
| 34 | + (getSeriesDetail as jest.Mock).mockResolvedValue({ |
| 35 | + totalSeasons: 1, |
| 36 | + seasons: [{ season: 1, episodes: [{ episode: 1 }] }], |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + afterEach(() => { |
| 41 | + jest.resetModules(); |
| 42 | + jest.clearAllMocks(); |
| 43 | + }); |
| 44 | + |
| 45 | + test('getView uses multiembed for series', async () => { |
| 46 | + (fetchOmdbData as jest.Mock).mockResolvedValue({}); |
| 47 | + const req: any = { params: { q: '', id: 'tt', type: 'series', season: '1', episode: '1' }, user: { id: 'u1' } }; |
| 48 | + const res: any = { locals: { APP_URL: 'http://app' }, render: jest.fn() }; |
| 49 | + await appController.getView(req, res, jest.fn()); |
| 50 | + expect(res.render).toHaveBeenCalledWith( |
| 51 | + 'view', |
| 52 | + expect.objectContaining({ |
| 53 | + iframeSrc: 'https://multi/?video_id=tt&s=1&e=1', |
| 54 | + server1Src: 'https://domain/embed/tv?imdb=tt&season=1&episode=1', |
| 55 | + server2Src: 'https://multi/?video_id=tt&s=1&e=1', |
| 56 | + currentServer: '2', |
| 57 | + }) |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + test('getView uses multiembed for movie', async () => { |
| 62 | + (fetchOmdbData as jest.Mock).mockResolvedValue({}); |
| 63 | + (History.findOneAndUpdate as jest.Mock).mockResolvedValue({ watched: false }); |
| 64 | + const req: any = { params: { q: '', id: 'tt', type: 'movie' }, user: { id: 'u1' } }; |
| 65 | + const res: any = { locals: { APP_URL: 'http://app' }, render: jest.fn() }; |
| 66 | + await appController.getView(req, res, jest.fn()); |
| 67 | + expect(res.render).toHaveBeenCalledWith( |
| 68 | + 'view', |
| 69 | + expect.objectContaining({ |
| 70 | + iframeSrc: 'https://multi/?video_id=tt', |
| 71 | + server1Src: 'https://domain/embed/movie/tt', |
| 72 | + server2Src: 'https://multi/?video_id=tt', |
| 73 | + currentServer: '2', |
| 74 | + }) |
| 75 | + ); |
| 76 | + }); |
| 77 | +}); |
0 commit comments