엑셀 양식 2단계: 일반 퀴즈 파일을 제목·가수·정답·가수 정답으로 나눔(정답은 ;로 여러 개, 제목·가수는 늘 정답, 내보내기는 제목·가수를 정답 칸 맨 앞에), 길이·비고 열. 예전 양식(정답=제목·설명·다른 정답)은 '제목' 열이 없으면 그대로 읽음. 파일 제목도 괄호·feat.·버전 표시를 지우고 괄호 안 다른 이름은 정답으로. 정답·가수 정답 칸이 빈 곡은 서버가 채움(POST /api/admin/quizzes/answers — 제목 정리 별칭 + 같은 DB 곡 별칭, answers/index.ts). 재생목록으로 엑셀 만들기: 일반 퀴즈용(정답·가수 정답·힌트)과 이지선다용(빈 조회수 열 → 파일로 만들기가 이지선다로 고름) 두 양식, 플레이리스트 가져오기 결과에 정리된 제목과 정답. 단위·API 테스트, e2e quiz(두 양식 받기)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-04 16:00:33 +09:00
parent 2e333dd3f7
commit 74eaeb85da
11 changed files with 331 additions and 117 deletions

View File

@@ -41,7 +41,11 @@ test('CSV: quotes, commas and line breaks inside, tab files, BOM, and Korean Exc
test('columns are found by their headers (the sent BGM sheet, our export, English)', () => {
expect(guessColumns(['번호', '유튜브 영상 링크', '게임 제목(한글)', '노래 제목', '힌트(게임장르)', '재생목록 순번'])).toEqual([null, 'link', 'answer', 'desc', 'hint', 'order']);
expect(guessColumns(quizToRows([]).rows[0] as string[])).toEqual(['order', 'link', 'answer', 'desc', 'hint', 'answers', 'descAnswers', 'start', 'highlight']);
expect(guessColumns(quizToRows([]).rows[0] as string[])).toEqual(['order', 'link', 'answer', 'desc', 'answers', 'descAnswers', 'hint', 'start', 'highlight', 'duration', null]);
// old 일반 퀴즈 files: 정답 is the title, 설명 / 다른 정답 / 설명 다른 정답
expect(guessColumns(['순번', '유튜브 영상 링크', '정답', '설명', '힌트', '다른 정답(;로 구분)', '설명 다른 정답(;로 구분)'])).toEqual(['order', 'link', 'answer', 'desc', 'hint', 'answers', 'descAnswers']);
// new ones (docs/13): 제목 next to 정답 → 정답 lists more answers
expect(guessColumns(['링크', '제목', '가수', '정답', '가수 정답', '비고'])).toEqual(['link', 'answer', 'desc', 'answers', 'descAnswers', null]);
expect(guessColumns(['URL', 'Title', 'Artist', 'Hint 1', 'Hint 2'])).toEqual(['link', 'answer', 'desc', 'hint', 'hint']);
// the header row may sit under a title line
expect(headerRow([['게임 BGM 모음'], ['링크', '정답'], ['x', 'y']])).toBe(1);
@@ -61,14 +65,36 @@ test('rows → quiz songs: as written, 순번 order, bad links / no answer / rep
const p = parseQuizRows(rows, guessColumns(rows[0]!), 0);
expect(p.items.map((i) => [i.videoId, i.title, i.artist, i.hints])).toEqual([
['x0-xFqvJ-U8', '갓 오브 워 2', 'The End Begins', ['확인필요']],
['iIIjS6yDMQo', '감옥탈출(구토할배)', '트레일러', ['방탈출(플래시)']],
['iIIjS6yDMQo', '감옥탈출', '트레일러', ['방탈출(플래시)']],
['Es6JbQQE79g', '번호 없음', '', []],
]);
expect(p.items.every((i) => i.fromFile && i.songId === null && i.auto)).toBe(true);
expect(p.rows.filter((r) => r.problem).map((r) => [r.line, r.problem])).toEqual([
[5, '유튜브 링크가 아니에요'],
[6, '2번째 줄과 같은 영상이에요'],
[7, '정답이 비어 있어요'],
[7, '제목이 비어 있어요'],
]);
// the bracket went from the title and stays an answer
expect(p.items[1]!.titleAnswers).toEqual(['구토할배', '감옥탈출 구토할배']);
});
test('일반 퀴즈 파일 (docs/13): 제목 cleaned, 정답 / 가수 정답 as written, empty ones marked for the server to fill', () => {
const rows = [
['링크', '제목', '가수', '정답', '가수 정답'],
['iIIjS6yDMQo', 'Pretender (feat. 누구)', 'Official髭男dism', 'Pretender; 프리텐더', '오피셜히게단디즘'],
['x0-xFqvJ-U8', '사랑을 했다(LOVE SCENARIO)', '아이콘', '', ''],
['Es6JbQQE79g', 'Finesse (Remix)', '', '', ''],
];
const p = parseQuizRows(rows, guessColumns(rows[0]!), 0);
expect(p.items.map((i) => [i.title, i.artist, i.titleAnswers, i.artistAnswers])).toEqual([
['Pretender', 'Official髭男dism', ['프리텐더'], ['오피셜히게단디즘']],
['사랑을 했다', '아이콘', ['LOVE SCENARIO', '사랑을 했다 LOVE SCENARIO'], []],
['Finesse', '', [], []],
]);
expect(p.rows.map((r) => r.fill)).toEqual([
{ title: false, artist: false },
{ title: true, artist: true },
{ title: true, artist: false },
]);
});
@@ -80,10 +106,8 @@ test('our export reads back to the same songs (answers, own positions, several h
const { rows } = quizToRows(items);
const text = rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
const back = parseQuizRows(text, guessColumns(text[0]!), 0).items;
expect(back).toEqual([
{ ...items[0]!, durationSec: null },
{ ...items[1]!, songId: null, fromFile: true, durationSec: null },
]);
expect(rows[1]!.slice(2, 6)).toEqual(['감옥탈출', '트레일러', '감옥탈출; 구토할배', '트레일러; trailer']);
expect(back).toEqual([items[0]!, { ...items[1]!, songId: null, fromFile: true }]);
const t = quizTemplateRows().rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(parseQuizRows(t, guessColumns(t[0]!), 0).items).toHaveLength(1);
});
@@ -132,14 +156,14 @@ test('이지선다 파일: 제목·가수, 조회수 optional (empty = fetched b
const fetched = { state: 'done' as const, topicId: 'aaaaaaaaaaa', topicViews: 10, mvId: 'bbbbbbbbbbb', mvViews: 20, error: null, at: 1 };
const withAuto = p.items.map((it, i) => (i === 1 ? { ...it, views: 30, viewsAuto: fetched } : it));
const { rows: out } = quizToRows(withAuto, 'duel');
expect(out[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)']);
expect(out[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)', '길이(초)', '비고']);
const text = out.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(parseQuizRows(text, guessColumns(text[0]!), 0, 'duel').items.map((i) => i.views)).toEqual([3456789, null, null]);
// nothing written by hand: no 조회수 column at all
expect(quizToRows([{ ...p.items[2]! }], 'duel').rows[0]).not.toContain('조회수');
// 빈 양식: no 조회수 column, the example row reads back with its views left to the server
const t = quizTemplateRows('duel').rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)']);
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)', '길이(초)', '비고']);
expect(parseQuizRows(t, guessColumns(t[0]!), 0, 'duel').items.map((i) => [i.title, i.views])).toEqual([['라일락', null]]);
});
@@ -154,43 +178,58 @@ test('재생목록으로 엑셀 만들기: kept songs with 비고, unplayable /
note: '',
...p,
});
const sheets = playlistSheets([
row({ n: 1, videoId: 'goodday0001', status: 'db', note: '서버 DB 곡 (플레이리스트 영상 사용)', title: '좋은 날', artist: '아이유', durationSec: 230 }),
const list = [
row({ n: 1, videoId: 'goodday0001', status: 'db', note: '서버 DB 곡 (플레이리스트 영상 사용)', title: '좋은 날', artist: '아이유', durationSec: 230, titleAnswers: ['Good Day'], artistAnswers: ['IU'] }),
row({ n: 2, videoId: 'lovedive001', note: '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)' }),
row({ n: 3, videoId: 'blocked0001', status: 'blocked', note: '다른 사이트 재생이 막힌 영상' }),
row({ n: 4, videoId: 'goodday0001', status: 'db' }),
row({ n: 5, status: 'missing', note: '유튜브에서 못 찾았어요' }),
row({ n: 6, videoId: 'hypeboy0001', status: 'check', note: '확인 필요: NewJeans - Hype Boy' }),
row({ n: 7, videoId: 'ditto000001', status: 'found', durationSec: null }),
]);
];
const sheets = playlistSheets(list);
expect(sheets.map((x) => x.name)).toEqual(['퀴즈', '빠진 곡']);
expect(sheets[0]!.rows).toEqual([
['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', null, null, 230, 'DB 곡'],
[2, 'https://youtu.be/lovedive001', '곡 2', '가수 2', null, null, 200, '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)'],
[3, 'https://youtu.be/hypeboy0001', '곡 6', '가수 6', null, null, 200, '확인 필요: NewJeans - Hype Boy'],
[4, 'https://youtu.be/ditto000001', '곡 7', '가수 7', null, null, null, '유튜브 뮤직에서 찾음'],
['순번', '유튜브 영상 링크', '제목', '가수', '정답(;로 구분)', '가수 정답(;로 구분)', '힌트', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', '좋은 날; Good Day', '아이유; IU', null, null, null, 230, 'DB 곡'],
[2, 'https://youtu.be/lovedive001', '곡 2', '가수 2', '곡 2', '가수 2', null, null, null, 200, '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)'],
[3, 'https://youtu.be/hypeboy0001', '곡 6', '가수 6', '곡 6', '가수 6', null, null, null, 200, '확인 필요: NewJeans - Hype Boy'],
[4, 'https://youtu.be/ditto000001', '곡 7', '가수 7', '곡 7', '가수 7', null, null, null, null, '유튜브 뮤직에서 찾음'],
]);
expect(sheets[1]!.rows.slice(1)).toEqual([
[3, 'https://youtu.be/blocked0001', '원래 3', '채널', '다른 사이트 재생이 막힌 영상'],
[4, 'https://youtu.be/goodday0001', '원래 4', '채널', '재생목록 1번 곡과 같은 영상'],
[5, '', '원래 5', '채널', '유튜브에서 못 찾았어요'],
]);
// the file as downloaded: 파일로 만들기 finds the columns by name, and the 빠진 곡 sheet gives no songs
const duel = playlistSheets(list, 'duel');
expect(duel[0]!.name).toBe('이지선다');
expect(duel[0]!.rows.slice(0, 2)).toEqual([
['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', null, null, null, 230, 'DB 곡'],
]);
// the files as downloaded: 파일로 만들기 finds the columns by name, and the 빠진 곡 sheet gives no songs
const book = await readSheetFile('재생목록.xlsx', writeXlsxSheets(sheets));
expect(book.map((x) => x.name)).toEqual(['퀴즈', '빠진 곡']);
const cols = guessColumns(book[0]!.rows[0]!);
expect(cols).toEqual(['order', 'link', 'answer', 'desc', 'start', 'highlight', 'duration', null]);
expect(cols).toEqual(['order', 'link', 'answer', 'desc', 'answers', 'descAnswers', 'hint', 'start', 'highlight', 'duration', null]);
expect(parseQuizRows(book[1]!.rows, guessColumns(book[1]!.rows[headerRow(book[1]!.rows)]!), headerRow(book[1]!.rows)).items).toEqual([]);
for (const kind of ['normal', 'duel'] as const) {
const items = parseQuizRows(book[0]!.rows, cols, 0, kind).items;
expect(items.map((i) => [i.videoId, i.title, i.artist, i.durationSec, i.auto])).toEqual([
['goodday0001', '좋은 날', '아이유', 230, true],
['lovedive001', '곡 2', '가수 2', 200, true],
['hypeboy0001', '곡 6', '가수 6', 200, true],
['ditto000001', '곡 7', '가수 7', null, true],
]);
}
const normal = parseQuizRows(book[0]!.rows, cols, 0).items;
expect(normal.map((i) => [i.videoId, i.title, i.artist, i.titleAnswers, i.artistAnswers, i.durationSec, i.auto])).toEqual([
['goodday0001', '좋은 날', '아이유', ['Good Day'], ['IU'], 230, true],
['lovedive001', '곡 2', '가수 2', [], [], 200, true],
['hypeboy0001', '곡 6', '가수 6', [], [], 200, true],
['ditto000001', '곡 7', '가수 7', [], [], null, true],
]);
// the 이지선다 file has the (empty) 조회수 column: 파일로 만들기 picks 이지선다 and leaves the views to the server
const duelBook = await readSheetFile('재생목록.xlsx', writeXlsxSheets(duel));
const duelCols = guessColumns(duelBook[0]!.rows[0]!);
expect(duelCols).toContain('views');
expect(parseQuizRows(duelBook[0]!.rows, duelCols, 0, 'duel').items.map((i) => [i.title, i.artist, i.views, i.durationSec])).toEqual([
['좋은 날', '아이유', null, 230],
['곡 2', '가수 2', null, 200],
['곡 6', '가수 6', null, 200],
['곡 7', '가수 7', null, null],
]);
});
test('시작·하이라이트가 빈 곡: 자동 (start 0 + highlight worked out) or 처음부터 (0 / 0); written values are kept either way', () => {