From 26ac9300300a0859840d5d38b57da0b8c7db3b6e Mon Sep 17 00:00:00 2001 From: 6-keem <6ukeem@gmail.com> Date: Sat, 24 Oct 2026 04:56:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=80=B4=EC=A6=88=20=EB=A7=81=ED=81=AC?= =?UTF-8?q?=EB=A5=BC=20getHref=20=EB=A1=9C=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=20=EC=A0=88=EB=8C=80=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit toQuizUrl 이 루트 상대 링크를 /mod/quiz/ 뒤에 그대로 이어 붙여 깨진 URL을 만들던 문제를 퀴즈 목록 페이지 URL 기준 getHref 로 대체해 해결한다. Closes #14 Co-Authored-By: Claude Opus 5.5 --- src/fetchQuiz.ts | 18 ++++-------------- test/fetchQuiz.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 test/fetchQuiz.test.ts diff --git a/src/fetchQuiz.ts b/src/fetchQuiz.ts index f1b3795..545efc6 100644 --- a/src/fetchQuiz.ts +++ b/src/fetchQuiz.ts @@ -1,6 +1,5 @@ -import { getText } from './dom.js'; +import { getHref, getText } from './dom.js'; import type { FetchHtml } from './types.js'; -import { BASE_LINK } from './links.js'; import { normalizeLmsDate } from './lmsKeywords.js'; import { isCurrentDateByDate } from './dateUtils.js'; @@ -12,15 +11,6 @@ const COL = { DUE_DATE: '.cell.c2', } as const; -/** - * 상대/절대 경로를 퀴즈 모듈 절대 URL로 변환 - * view.php?id=123 → https://learn.hansung.ac.kr/mod/quiz/view.php?id=123 - */ -function toQuizUrl(rawHref: string): string { - if (rawHref.startsWith('http')) return rawHref; - return `${BASE_LINK}/mod/quiz/${rawHref}`; -} - /** * 퀴즈 상세 페이지에서 제출 여부를 확인 * quizattemptsummary 테이블에 행이 있으면 제출된 것으로 판단 @@ -67,10 +57,10 @@ export const fetchQuiz = async ( const dueDate = rawDueDate && rawDueDate !== '-' ? (normalizeLmsDate(rawDueDate) ?? null) : null; const title = titleLink.textContent?.trim(); - const rawHref = titleLink.getAttribute('href'); - if (!title || !rawHref) return []; + const url = getHref(row, COL.TITLE_LINK, link); + if (!title || !url) return []; - return { title, subject: lastWeekLabel, url: toQuizUrl(rawHref), dueDate }; + return { title, subject: lastWeekLabel, url, dueDate }; }); // 마감 전 퀴즈만 상세 페이지 fetch, 마감된 퀴즈는 캐시 사용 diff --git a/test/fetchQuiz.test.ts b/test/fetchQuiz.test.ts new file mode 100644 index 0000000..113a9e2 --- /dev/null +++ b/test/fetchQuiz.test.ts @@ -0,0 +1,25 @@ +import { describe, it, expect } from 'vitest'; +import { fetchQuiz } from '../src/fetchQuiz.js'; +import { getQuizPageLink } from '../src/links.js'; +import type { FetchHtml } from '../src/types.js'; + +const LIST_URL = getQuizPageLink('123'); +const QUIZ_URL = 'https://learn.hansung.ac.kr/mod/quiz/view.php?id=9'; + +const fetchWithHref = + (href: string): FetchHtml => + async (url) => { + const html = + url === LIST_URL + ? ` +
1주차퀴즈1-
` + : ''; + return new DOMParser().parseFromString(`${html}`, 'text/html'); + }; + +describe('fetchQuiz 링크 절대화', () => { + it.each(['view.php?id=9', '/mod/quiz/view.php?id=9', QUIZ_URL])('%s → 퀴즈 절대 URL', async (href) => { + const [quiz] = await fetchQuiz(fetchWithHref(href), LIST_URL); + expect(quiz.url).toBe(QUIZ_URL); + }); +});