diff --git a/apps/server/src/duel-views.test.ts b/apps/server/src/duel-views.test.ts index 96154bf..792ac16 100644 --- a/apps/server/src/duel-views.test.ts +++ b/apps/server/src/duel-views.test.ts @@ -68,6 +68,10 @@ test('fetchDuelViews: either half may be linked; a song with one half keeps that expect(mvOnly).toMatchObject({ topicId: null, mvId: 'onlyMV00001', mvViews: 20 }); // any other upload without a 토픽 pair: that video's views expect(await fetchDuelViews('fanUpload01', src, 1)).toMatchObject({ topicId: null, mvId: 'fanUpload01', mvViews: 7 }); + // signed in but the video is not in the answer (empty or changed response): unknown, not "토픽 없음" + const empty = { ...src, songPair: async () => parseSongPair(watch([]), 'lilacMV0001') }; + await expect(fetchDuelViews('lilacMV0001', empty, 1)).rejects.toThrow('곡 정보를 찾지 못했어요'); + expect(src.calls.filter((c) => c === 'views lilacMV0001')).toHaveLength(2); // 비고 const it = (viewsAuto: DuelViews | null, views: number | null = 1, fromFile = true) => duelViewsNote({ views, viewsAuto, fromFile }); expect(it(both as DuelViews)).toBeNull(); @@ -84,7 +88,7 @@ test('youtubeViewCount: the player count, else the watch page count, else an err expect(await youtubeViewCount('v7bnOxV4jAc', fake({ videoDetails: { videoId: 'v7bnOxV4jAc', viewCount: '120456684' } }, ''))).toBe(120456684); const page = '{"videoViewCountRenderer":{"viewCount":{"simpleText":"조회수 120,456,684회"}}}'; expect(await youtubeViewCount('v7bnOxV4jAc', fake({ playabilityStatus: { status: 'LOGIN_REQUIRED' } }, page))).toBe(120456684); - expect(youtubeViewCount('v7bnOxV4jAc', fake({}, '{}'))).rejects.toThrow('조회수를 찾지 못했어요'); + await expect(youtubeViewCount('v7bnOxV4jAc', fake({}, '{}'))).rejects.toThrow('조회수를 찾지 못했어요'); }); // ------------------------------------------------------------------ upload → fetch → editor diff --git a/apps/server/src/quizzes/duel-views.ts b/apps/server/src/quizzes/duel-views.ts index 28d2d8d..815eae4 100644 --- a/apps/server/src/quizzes/duel-views.ts +++ b/apps/server/src/quizzes/duel-views.ts @@ -20,6 +20,8 @@ const UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Geck /** The linked video may be either half: a 토픽 pairs with its MV, anything else (MV, other upload) with its 토픽. */ export async function fetchDuelViews(videoId: string, src: ViewsSource, now = Date.now()): Promise { const pair = await src.songPair(videoId); + // the video is not in the answer at all: nothing is known about its pair, so this is no "토픽 없음" + if (!pair.type) throw new Error('유튜브 뮤직에서 이 영상의 곡 정보를 찾지 못했어요'); const selfTopic = pair.type === TOPIC; const topicId = selfTopic ? videoId : pair.other?.type === TOPIC ? pair.other.videoId : null; const mvId = !selfTopic ? videoId : pair.other && pair.other.type !== TOPIC ? pair.other.videoId : null;