diff --git a/server/src/Core/LiveStreamDVR.ts b/server/src/Core/LiveStreamDVR.ts index 6525590a..db5a1069 100644 --- a/server/src/Core/LiveStreamDVR.ts +++ b/server/src/Core/LiveStreamDVR.ts @@ -210,6 +210,25 @@ export class LiveStreamDVR { // TwitchHelper.refreshUserAccessToken(); } + public static migrateChannelConfig(channel: ChannelConfig): void { + if (channel.provider == "twitch") { + if (!channel.internalName && channel.login) { + channel.internalName = channel.login; + } + } else if (channel.provider == "youtube") { + if (!channel.internalName && channel.channel_id) { + channel.internalName = channel.channel_id; + } + if (!channel.internalId && channel.channel_id) { + channel.internalId = channel.channel_id; + } + } else if (channel.provider == "kick") { + if (!channel.internalName && channel.slug) { + channel.internalName = channel.slug; + } + } + } + /** * @test disable * @returns @@ -255,6 +274,8 @@ export class LiveStreamDVR { ); needsSave = true; } + + /* if (!channel.internalName || !channel.internalId) { if (channel.provider == "twitch") { channel.internalName = channel.login || ""; @@ -267,6 +288,8 @@ export class LiveStreamDVR { // throw new Error(`Channel ${channel.uuid} does not have an internalName`); } } + */ + LiveStreamDVR.migrateChannelConfig(channel); } this.channels_config = data; @@ -324,9 +347,7 @@ export class LiveStreamDVR { let ch: TwitchChannel; try { - ch = await TwitchChannel.loadFromLogin( - channel.internalName - ); + ch = await TwitchChannel.load(channel.uuid); } catch (th) { log( LOGLEVEL.FATAL, diff --git a/server/src/Core/Providers/Twitch/TwitchChannel.ts b/server/src/Core/Providers/Twitch/TwitchChannel.ts index 6d86d0dd..ab20fc95 100644 --- a/server/src/Core/Providers/Twitch/TwitchChannel.ts +++ b/server/src/Core/Providers/Twitch/TwitchChannel.ts @@ -1653,32 +1653,43 @@ export class TwitchChannel extends BaseChannel { // TODO: load by uuid? public static async loadAbstract( - channel_id: string + // channel_id: string + uuid: string ): Promise { - log( - LOGLEVEL.DEBUG, - "tw.channel.loadAbstract", - `Load channel ${channel_id}` - ); + log(LOGLEVEL.DEBUG, "tw.channel.loadAbstract", `Load channel ${uuid}`); const channel_memory = LiveStreamDVR.getInstance() .getChannels() .find( (channel): channel is TwitchChannel => - isTwitchChannel(channel) && - channel.internalId === channel_id + isTwitchChannel(channel) && channel.uuid === uuid ); if (channel_memory) { log( LOGLEVEL.WARNING, "tw.channel.loadAbstract", - `Channel ${channel_id} already loaded` + `Channel ${uuid} (${channel_memory.internalName}) already exists in memory, returning` ); return channel_memory; } + const channel_config = LiveStreamDVR.getInstance().channels_config.find( + (c) => c.provider == "twitch" && c.uuid === uuid + ); + + if (!channel_config) + throw new Error(`Could not find channel config for uuid ${uuid}`); + + const channel_id = + channel_config.internalId || + (await this.channelIdFromLogin(channel_config.internalName)); + + if (!channel_id) + throw new Error( + `Could not get channel id for login ${channel_config.internalName}` + ); + const channel = new this(); - // channel.userid = channel_id; const channel_data = await this.getUserDataById(channel_id); if (!channel_data) @@ -1688,16 +1699,6 @@ export class TwitchChannel extends BaseChannel { const channel_login = channel_data.login; - const channel_config = LiveStreamDVR.getInstance().channels_config.find( - (c) => - c.provider == "twitch" && - (c.login === channel_login || c.internalName === channel_login) - ); - if (!channel_config) - throw new Error( - `Could not find channel config in memory for channel login: ${channel_login}` - ); - channel.uuid = channel_config.uuid; channel.channel_data = channel_data; channel.config = channel_config; @@ -1826,11 +1827,11 @@ export class TwitchChannel extends BaseChannel { public static async create( config: TwitchChannelConfig ): Promise { + // check if channel already exists in config const exists_config = LiveStreamDVR.getInstance().channels_config.find( (ch) => ch.provider == "twitch" && - (ch.login === config.login || - ch.internalName === config.login || + (ch.login === config.internalName || ch.internalName === config.internalName) ); if (exists_config) @@ -1838,6 +1839,7 @@ export class TwitchChannel extends BaseChannel { `Channel ${config.internalName} already exists in config` ); + // check if channel already exists in memory const exists_channel = LiveStreamDVR.getInstance() .getChannels() .find( @@ -1850,6 +1852,7 @@ export class TwitchChannel extends BaseChannel { `Channel ${config.internalName} already exists in channels` ); + // fetch channel data const data = await TwitchChannel.getUserDataByLogin( config.internalName ); @@ -1863,7 +1866,8 @@ export class TwitchChannel extends BaseChannel { LiveStreamDVR.getInstance().channels_config.push(config); LiveStreamDVR.getInstance().saveChannelsConfig(); - const channel = await TwitchChannel.loadFromLogin(config.internalName); + // const channel = await TwitchChannel.loadFromLogin(config.internalName); + const channel = await TwitchChannel.load(config.uuid); if (!channel || !channel.internalName) throw new Error( `Channel ${config.internalName} could not be loaded` @@ -2006,7 +2010,7 @@ export class TwitchChannel extends BaseChannel { let response; if (!TwitchHelper.hasAxios()) { - throw new Error("Axios is not initialized"); + throw new Error("Axios is not initialized (getStreams)"); } try { @@ -2047,26 +2051,24 @@ export class TwitchChannel extends BaseChannel { return json.data ?? false; } - /** - * Load channel class using login, don't call this. Used internally. - * - * @internal - * @param login - * @returns - */ - public static async loadFromLogin(login: string): Promise { - if (!login) throw new Error("Streamer login is empty"); - if (typeof login !== "string") - throw new TypeError("Streamer login is not a string"); - log( - LOGLEVEL.DEBUG, - "tw.channel.loadFromLogin", - `Load from login ${login}` + public static async load(uuid: string): Promise { + /* + const channel_config = LiveStreamDVR.getInstance().channels_config.find( + (c) => c.uuid === uuid ); - const channel_id = await this.channelIdFromLogin(login); - if (!channel_id) - throw new Error(`Could not get channel id from login: ${login}`); - return this.loadAbstract(channel_id); // $channel; + if (!channel_config) + throw new Error(`Could not find channel config for uuid: ${uuid}`); + + const channel_data = await this.getUserDataByLogin( + channel_config.internalName + ); + + if (!channel_data) + throw new Error( + `Could not get channel data for channel login: ${channel_config.internalName}` + ); + */ + return await this.loadAbstract(uuid); } public static async channelIdFromLogin( @@ -2141,6 +2143,10 @@ export class TwitchChannel extends BaseChannel { `Fetching user data for ${method} ${identifier}, force: ${force}` ); + if (identifier == undefined || identifier == null || identifier == "") { + throw new Error(`getUserDataProxy: identifier is empty`); + } + // check cache first if (!force) { const channelData = @@ -2202,7 +2208,7 @@ export class TwitchChannel extends BaseChannel { */ if (!TwitchHelper.hasAxios()) { - throw new Error("Axios is not initialized"); + throw new Error("Axios is not initialized (getUserDataProxy)"); } let response; @@ -2478,7 +2484,7 @@ export class TwitchChannel extends BaseChannel { ); if (!TwitchHelper.hasAxios()) { - throw new Error("Axios is not initialized"); + throw new Error("Axios is not initialized (getChannelDataById)"); } let response; @@ -2660,7 +2666,9 @@ export class TwitchChannel extends BaseChannel { }; if (!TwitchHelper.hasAxios()) { - throw new Error("Axios is not initialized"); + throw new Error( + "Axios is not initialized (subscribeToIdWithWebhook)" + ); } let response; @@ -3006,7 +3014,9 @@ export class TwitchChannel extends BaseChannel { }; if (!TwitchHelper.hasAxios()) { - throw new Error("Axios is not initialized"); + throw new Error( + "Axios is not initialized (subscribeToIdWithWebsocket)" + ); } let response; diff --git a/server/tests/api.test.ts b/server/tests/api.test.ts index 85ba132d..e708bf92 100644 --- a/server/tests/api.test.ts +++ b/server/tests/api.test.ts @@ -17,7 +17,7 @@ import "./environment"; // jest.mock("../src/Core/TwitchChannel"); let app: Express | undefined; -let spy1: jest.SpyInstance | undefined; +// let spy1: jest.SpyInstance | undefined; // jest.mock("../src/Providers/Twitch"); // jest.mock("../src/Core/Config"); @@ -60,26 +60,30 @@ beforeAll(async () => { app.use("", baserouter); // TwitchChannel.getChannelDataProxy + /* spy1 = jest .spyOn(TwitchChannel, "getUserDataProxy") - .mockImplementation(() => { - return Promise.resolve({ - provider: "twitch", - id: "12345", - login: "test", - display_name: "test", - type: "", - broadcaster_type: "partner", - description: "test", - profile_image_url: "test", - offline_image_url: "test", - view_count: 0, - created_at: "test", - _updated: 1234, - cache_avatar: "test", - cache_offline_image: "", - } as UserData); - }); + .mockImplementation( + (method: string, identifier: string, force: boolean) => { + return Promise.resolve({ + provider: "twitch", + id: "1234", + login: identifier, + display_name: identifier, + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + } as UserData); + } + ); + */ }); // afterEach(() => { @@ -90,7 +94,7 @@ afterAll(() => { Config.destroyInstance(); LiveStreamDVR.shutdown("test", true); app = undefined; - spy1?.mockRestore(); + // spy1?.mockRestore(); jest.restoreAllMocks(); }); @@ -188,9 +192,47 @@ describe("channels", () => { download_vod_at_end_quality: "best", }; + const add_data2 = { + provider: "twitch", + internalName: "test2", + quality: "best 1080p60", + match: "", + download_chat: true, + live_chat: false, + burn_chat: false, + no_capture: false, + no_cleanup: true, + max_storage: 2, + max_vods: 5, + download_vod_at_end: false, + download_vod_at_end_quality: "best", + }; + it("should add a channel in isolated mode", async () => { Config.getInstance().setConfig("app_url", ""); Config.getInstance().setConfig("isolated_mode", true); + + const spy = jest + .spyOn(TwitchChannel, "getUserDataProxy") + .mockReturnValue( + Promise.resolve({ + provider: "twitch", + id: "1234", + login: "test", + display_name: "test", + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + } as UserData) + ); + const res3 = await request(app).post("/api/v0/channels").send(add_data); expect(res3.body.message).toContain("'test' created"); expect(res3.body.data).toHaveProperty("displayName"); @@ -198,10 +240,14 @@ describe("channels", () => { LiveStreamDVR.getInstance().clearChannels(); LiveStreamDVR.getInstance().channels_config = []; + + spy.mockRestore(); }); - it("should not add a channel", async () => { - spy1?.mockClear(); + it("should not add a channel because of quality mismatch", async () => { + // spy1?.mockClear(); + + const spy = jest.spyOn(TwitchChannel, "getUserDataProxy"); const res = await request(app).post("/api/v0/channels").send({ provider: "twitch", @@ -217,17 +263,43 @@ describe("channels", () => { expect(res.status).toBe(400); // expect(res.body.message).toContain("Invalid quality"); - expect(spy1).not.toHaveBeenCalled(); + // expect(spy1).not.toHaveBeenCalled(); + expect(spy).not.toHaveBeenCalled(); + spy.mockRestore(); }); it("should fail adding channel due to subscribe stuff", async () => { // both disabled Config.getInstance().setConfig("app_url", ""); Config.getInstance().setConfig("isolated_mode", false); + + const spy = jest + .spyOn(TwitchChannel, "getUserDataProxy") + .mockReturnValue( + Promise.resolve({ + provider: "twitch", + id: "1234", + login: "test", + display_name: "test", + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + } as UserData) + ); + const res1 = await request(app).post("/api/v0/channels").send(add_data); expect(res1.body.message).toContain("no app_url"); expect(res1.status).toBe(400); + spy.mockRestore(); + // debug app url // Config.getInstance().setConfig("app_url", "debug"); // Config.getInstance().setConfig("isolated_mode", false); @@ -253,9 +325,31 @@ describe("channels", () => { it("should add a channel", async () => { Config.getInstance().setConfig("app_url", "https://example.com"); Config.getInstance().setConfig("isolated_mode", false); + + const spy = jest + .spyOn(TwitchChannel, "getUserDataProxy") + .mockReturnValue( + Promise.resolve({ + provider: "twitch", + id: "1234", + login: "test", + display_name: "test", + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + } as UserData) + ); + const res4 = await request(app).post("/api/v0/channels").send(add_data); expect(res4.body.message).toContain("'test' created"); - expect(res4.body.data).toHaveProperty("display_name"); + expect(res4.body.data).toHaveProperty("displayName"); expect(res4.status).toBe(200); uuid = res4.body.data.uuid; @@ -264,8 +358,10 @@ describe("channels", () => { // TwitchChannel.channels = []; // TwitchChannel.channels_config = []; - expect(spy1).toHaveBeenCalled(); + // expect(spy1).toHaveBeenCalled(); + expect(spy).toHaveBeenCalled(); expect(TwitchChannel.subscribeToIdWithWebhook).toHaveBeenCalled(); + spy.mockRestore(); Config.getInstance().setConfig("app_url", ""); Config.getInstance().setConfig("isolated_mode", false); @@ -289,7 +385,7 @@ describe("channels", () => { expect(uuid).not.toBe(""); const channel_res = await request(app).get(`/api/v0/channels/${uuid}`); expect(channel_res.status).toBe(200); - expect(channel_res.body.data).toHaveProperty("display_name"); + expect(channel_res.body.data).toHaveProperty("displayName"); }); it("added channel should be in channels list", async () => { @@ -297,18 +393,97 @@ describe("channels", () => { const channels_res = await request(app).get("/api/v0/channels"); expect(channels_res.status).toBe(200); expect(channels_res.body.data.streamer_list).toHaveLength(1); - expect(channels_res.body.data.streamer_list[0].display_name).toBe( + expect(channels_res.body.data.streamer_list[0].displayName).toBe( "test" ); }); it("should remove a channel", async () => { const res = await request(app).delete(`/api/v0/channels/${uuid}`); + expect(res.status).toBe(200); expect(res.body.message).toContain("'test' deleted"); expect(res.body.status).toBe("OK"); - expect(res.status).toBe(200); expect(TwitchChannel.unsubscribeFromIdWithWebhook).toHaveBeenCalled(); }); + + it("two channels should be added", async () => { + LiveStreamDVR.getInstance().clearChannels(); + LiveStreamDVR.getInstance().channels_config = []; + Config.getInstance().setConfig("app_url", "https://example.com"); + + let spy = jest + .spyOn(TwitchChannel, "getUserDataProxy") + .mockImplementation( + (method: string, identifier: string, force: boolean) => + Promise.resolve({ + provider: "twitch", + id: "1234", + login: "test", + display_name: "test", + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + }) + ); + + const res1 = await request(app).post("/api/v0/channels").send(add_data); + expect(res1.body.message).toContain("'test' created"); + expect(res1.status).toBe(200); + expect(TwitchChannel.subscribeToIdWithWebhook).toHaveBeenCalled(); + + spy.mockRestore(); + + spy = jest + .spyOn(TwitchChannel, "getUserDataProxy") + .mockImplementation( + (method: string, identifier: string, force: boolean) => + Promise.resolve({ + provider: "twitch", + id: "1234", + login: "test2", + display_name: "test2", + type: "", + broadcaster_type: "partner", + description: "test", + profile_image_url: "test", + offline_image_url: "test", + view_count: 0, + created_at: "test", + _updated: 1234, + cache_avatar: "test", + cache_offline_image: "", + }) + ); + + const res2 = await request(app) + .post("/api/v0/channels") + .send(add_data2); + expect(res2.body.message).toContain("'test2' created"); + expect(res2.status).toBe(200); + expect(TwitchChannel.subscribeToIdWithWebhook).toHaveBeenCalled(); + + spy.mockRestore(); + + const channels_res = await request(app).get("/api/v0/channels"); + expect(channels_res.status).toBe(200); + expect(channels_res.body.data.streamer_list).toHaveLength(2); + expect(channels_res.body.data.streamer_list[0].displayName).toBe( + "test" + ); + expect(channels_res.body.data.streamer_list[1].displayName).toBe( + "test2" + ); + + LiveStreamDVR.getInstance().clearChannels(); + LiveStreamDVR.getInstance().channels_config = []; + }); }); describe("auth", () => { diff --git a/server/tests/environment.ts b/server/tests/environment.ts index cc9ea810..3d4aab82 100644 --- a/server/tests/environment.ts +++ b/server/tests/environment.ts @@ -1,17 +1,16 @@ +import { Config } from "../src/Core/Config"; +import { Job } from "../src/Core/Job"; +import { KeyValue } from "../src/Core/KeyValue"; +import { LiveStreamDVR } from "../src/Core/LiveStreamDVR"; import * as LogModule from "../src/Core/Log"; import { BaseChannel } from "../src/Core/Providers/Base/BaseChannel"; import { BaseVOD } from "../src/Core/Providers/Base/BaseVOD"; import { TwitchChannel } from "../src/Core/Providers/Twitch/TwitchChannel"; +import { TwitchGame } from "../src/Core/Providers/Twitch/TwitchGame"; import { TwitchVOD } from "../src/Core/Providers/Twitch/TwitchVOD"; import { YouTubeVOD } from "../src/Core/Providers/YouTube/YouTubeVOD"; -import { Config } from "../src/Core/Config"; -import { LiveStreamDVR } from "../src/Core/LiveStreamDVR"; import { Scheduler } from "../src/Core/Scheduler"; import { TwitchHelper } from "../src/Providers/Twitch"; -import { AppRoot, DataRoot } from "../src/Core/BaseConfig"; -import { KeyValue } from "../src/Core/KeyValue"; -import { TwitchGame } from "../src/Core/Providers/Twitch/TwitchGame"; -import { Job } from "../src/Core/Job"; /* // dangerous methods that need to be mocked/disabled for tests @@ -50,52 +49,170 @@ Job.loadJobsFromCache // mock methods beforeAll(() => { - jest.spyOn(Config.prototype, "loadConfig").mockImplementation(function(this: Config) { + jest.spyOn(Config.prototype, "loadConfig").mockImplementation(function ( + this: Config + ) { this.generateConfig(); return true; }); - jest.spyOn(Config.prototype, "saveConfig").mockImplementation(() => { return true; }); - jest.spyOn(Config.prototype, "startWatchingConfig").mockImplementation(() => { console.debug("Disable start watching config"); return; }); - jest.spyOn(Config, "checkBuiltDependencies").mockImplementation(() => { return; }); - jest.spyOn(Config, "checkAppRoot").mockImplementation(() => { return; }); - jest.spyOn(Config, "createFolders").mockImplementation(() => { return; }); - jest.spyOn(KeyValue.prototype, "save").mockImplementation(() => { return; }); - jest.spyOn(KeyValue.prototype, "load").mockImplementation(() => { return; }); - jest.spyOn(LiveStreamDVR.prototype, "loadChannelsConfig").mockImplementation(() => { return true; }); - jest.spyOn(LiveStreamDVR.prototype, "saveChannelsConfig").mockImplementation(() => { return true; }); - jest.spyOn(LiveStreamDVR.prototype, "startDiskSpaceInterval").mockImplementation(() => { return true; }); - jest.spyOn(LiveStreamDVR, "checkBinaryVersions").mockImplementation(() => { return Promise.resolve(); }); - jest.spyOn(LiveStreamDVR, "checkVersion").mockImplementation(() => { return; }); + jest.spyOn(Config.prototype, "saveConfig").mockImplementation(() => { + return true; + }); + jest.spyOn(Config.prototype, "startWatchingConfig").mockImplementation( + () => { + console.debug("Disable start watching config"); + return; + } + ); + jest.spyOn(Config, "checkBuiltDependencies").mockImplementation(() => { + return; + }); + jest.spyOn(Config, "checkAppRoot").mockImplementation(() => { + return; + }); + jest.spyOn(Config, "createFolders").mockImplementation(() => { + return; + }); + jest.spyOn(KeyValue.prototype, "save").mockImplementation(() => { + return; + }); + jest.spyOn(KeyValue.prototype, "load").mockImplementation(() => { + return; + }); + jest.spyOn( + LiveStreamDVR.prototype, + "loadChannelsConfig" + ).mockImplementation(() => { + return true; + }); + jest.spyOn( + LiveStreamDVR.prototype, + "saveChannelsConfig" + ).mockImplementation(() => { + return true; + }); + jest.spyOn( + LiveStreamDVR.prototype, + "startDiskSpaceInterval" + ).mockImplementation(() => { + return true; + }); + jest.spyOn(LiveStreamDVR, "checkBinaryVersions").mockImplementation(() => { + return Promise.resolve(); + }); + jest.spyOn(LiveStreamDVR, "checkVersion").mockImplementation(() => { + return; + }); // jest.spyOn(Log, "logAdvanced").mockImplementation((level, module, text, meta) => { // console.log(`[TEST][${level}] ${module}: ${text}`); // return; // }); // logAdvanced is now a regular export at the top of the file, not a class method - jest.spyOn(LogModule, "log").mockImplementation((level, module, text, meta) => { - console.log(`[TEST][${level}] ${module}: ${text}`); + jest.spyOn(LogModule, "log").mockImplementation( + (level, module, text, meta) => { + console.log(`[TEST][${level}] ${module}: ${text}`); + return; + } + ); + jest.spyOn(Scheduler, "defaultJobs").mockImplementation(() => { + return; + }); + jest.spyOn(BaseChannel.prototype, "broadcastUpdate").mockImplementation( + () => { + return; + } + ); + jest.spyOn(BaseChannel.prototype, "saveVodDatabase").mockImplementation( + () => { + return; + } + ); + jest.spyOn(BaseChannel.prototype, "findClips").mockImplementation(() => { + return Promise.resolve(); + }); + jest.spyOn(BaseChannel.prototype, "makeFolder").mockImplementation(() => { + return; + }); + jest.spyOn(BaseVOD.prototype, "startWatching").mockImplementation(() => { + console.debug("Disable start watching basevod"); + return Promise.resolve(true); + }); + jest.spyOn(BaseVOD.prototype, "broadcastUpdate").mockImplementation(() => { return; }); - jest.spyOn(Scheduler, "defaultJobs").mockImplementation(() => { return; }); - jest.spyOn(BaseChannel.prototype, "broadcastUpdate").mockImplementation(() => { return; }); - jest.spyOn(BaseChannel.prototype, "saveVodDatabase").mockImplementation(() => { return; }); - jest.spyOn(BaseChannel.prototype, "findClips").mockImplementation(() => { return Promise.resolve(); }); - jest.spyOn(BaseChannel.prototype, "makeFolder").mockImplementation(() => { return; }); - jest.spyOn(BaseVOD.prototype, "startWatching").mockImplementation(() => { console.debug("Disable start watching basevod"); return Promise.resolve(true); }); - jest.spyOn(BaseVOD.prototype, "broadcastUpdate").mockImplementation(() => { return; }); - jest.spyOn(TwitchChannel.prototype, "startWatching").mockImplementation(() => { console.debug("Disable start watching twitchchannel"); return Promise.resolve(); }); - jest.spyOn(TwitchChannel, "loadChannelsCache").mockImplementation(() => { return true; }); - jest.spyOn(TwitchChannel, "getUserDataProxy").mockImplementation(() => { return Promise.resolve(false); }); - jest.spyOn(TwitchVOD.prototype, "startWatching").mockImplementation(() => { console.debug("Disable start watching twitchvod"); return Promise.resolve(true); }); - jest.spyOn(TwitchVOD.prototype, "saveJSON").mockImplementation(() => { return Promise.resolve(true); }); - jest.spyOn(YouTubeVOD.prototype, "saveJSON").mockImplementation(() => { return Promise.resolve(true); }); - jest.spyOn(TwitchChannel, "subscribeToIdWithWebhook").mockImplementation(() => { return Promise.resolve(true); }); - jest.spyOn(TwitchChannel, "unsubscribeFromIdWithWebhook").mockImplementation(() => { return Promise.resolve(true); }); - jest.spyOn(TwitchChannel, "subscribeToIdWithWebsocket").mockImplementation(() => { return Promise.resolve(true); }); + jest.spyOn(TwitchChannel.prototype, "startWatching").mockImplementation( + () => { + console.debug("Disable start watching twitchchannel"); + return Promise.resolve(); + } + ); + jest.spyOn(TwitchChannel, "loadChannelsCache").mockImplementation(() => { + return true; + }); + /* + jest.spyOn(TwitchChannel, "getUserDataProxy").mockImplementation(() => { + return Promise.resolve(false); + }); + jest.spyOn(TwitchChannel, "getUserDataByLogin").mockImplementation( + (login: string, force?: boolean) => { + return Promise.resolve({ + login: login, + _updated: 1, + cache_offline_image: "", + profile_image_url: "", + offline_image_url: "", + created_at: "", + id: "1234", + avatar_cache: "", + avatar_thumb: "", + broadcaster_type: "partner", + display_name: login, + type: "", + description: "", + view_count: 0, + }); + } + ); + */ + jest.spyOn(TwitchVOD.prototype, "startWatching").mockImplementation(() => { + console.debug("Disable start watching twitchvod"); + return Promise.resolve(true); + }); + jest.spyOn(TwitchVOD.prototype, "saveJSON").mockImplementation(() => { + return Promise.resolve(true); + }); + jest.spyOn(YouTubeVOD.prototype, "saveJSON").mockImplementation(() => { + return Promise.resolve(true); + }); + jest.spyOn(TwitchChannel, "subscribeToIdWithWebhook").mockImplementation( + () => { + return Promise.resolve(true); + } + ); + jest.spyOn( + TwitchChannel, + "unsubscribeFromIdWithWebhook" + ).mockImplementation(() => { + return Promise.resolve(true); + }); + jest.spyOn(TwitchChannel, "subscribeToIdWithWebsocket").mockImplementation( + () => { + return Promise.resolve(true); + } + ); // jest.spyOn(TwitchChannel, "unsubscribeFromIdWithWebsocket").mockImplementation(() => { return Promise.resolve(true); }); - jest.spyOn(TwitchHelper, "getAccessToken").mockImplementation(() => { return Promise.resolve("test"); }); - jest.spyOn(TwitchGame, "populateFavouriteGames").mockImplementation(() => { return Promise.resolve(); }); - jest.spyOn(TwitchGame, "populateGameDatabase").mockImplementation(() => { return Promise.resolve(); }); - jest.spyOn(Job, "loadJobsFromCache").mockImplementation(() => { return; }); + jest.spyOn(TwitchHelper, "getAccessToken").mockImplementation(() => { + return Promise.resolve("test"); + }); + jest.spyOn(TwitchGame, "populateFavouriteGames").mockImplementation(() => { + return Promise.resolve(); + }); + jest.spyOn(TwitchGame, "populateGameDatabase").mockImplementation(() => { + return Promise.resolve(); + }); + jest.spyOn(Job, "loadJobsFromCache").mockImplementation(() => { + return; + }); // mock data consts // jest.spyOn(AppRoot, "get").mockImplementation(() => { return "test"; });