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