재생목록으로 엑셀 만들기: 관리자 → 퀴즈 목록 카드. 플레이리스트 가져오기와 같은 검토(서버 DB 곡, 영상 제목 정리, 스포티파이는 유튜브 뮤직 검색, 다른 사이트 재생 확인) 결과를 파일로 만들기가 그대로 읽는 엑셀로 받음 — 시트 '퀴즈'(순번·유튜브 영상 링크·제목·가수·시작(초)·하이라이트(초)·길이(초)·비고)와 '빠진 곡'(재생 막힘·없는 영상·못 찾은 곡·같은 영상, 이유와 함께; 제목 열이 없어 곡으로 읽히지 않음). 비고: DB 곡 / 제목·가수 확인 필요(영상 제목에 가수-제목 형식이 없어 채널 이름을 가수로 씀, 플레이리스트 가져오기에도 표시) / 확인 필요 / 유튜브 뮤직에서 찾음. 조회수 열은 넣지 않음(이지선다는 서버가 불러옴). 파일로 만들기·파일에서 가져오기: '시작·하이라이트가 빈 곡: 자동 / 처음부터' 선택(처음부터 = 0/0으로 적어 하이라이트부터 방에서도 처음부터), 길이(초) 열 읽기. 파일로 만들기의 자동 곡은 서버 DB에 같은 영상이 있으면 그 하이라이트(직접 위치로)와 길이를 씀 — 파일 곡은 DB와 연결하지 않아 자동이 늘 처음부터였던 것. writeXlsxSheets(여러 시트). 단위·API 테스트, e2e quiz 단계, docs 10·12

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-03 23:20:04 +09:00
parent 8a52fd3b68
commit 70edadfe36
13 changed files with 441 additions and 40 deletions

View File

@@ -1,8 +1,8 @@
/** 퀴즈 파일: .xlsx / .csv reading and writing, column guessing, rows → quiz songs. */
import { expect, test } from 'bun:test';
import { decodeCsv, parseCsv, readSheetFile, readXlsx, writeXlsx } from './sheet';
import { decodeCsv, parseCsv, readSheetFile, readXlsx, writeXlsx, writeXlsxSheets } from './sheet';
import { deflatedZip } from './zip-fixture';
import { guessColumns, headerRow, parseQuizRows, parseSec, parseVideoId, parseViews, quizTemplateRows, quizToRows } from './quiz-file';
import { guessColumns, headerRow, parseQuizRows, parseSec, parseVideoId, parseViews, playlistSheets, quizTemplateRows, quizToRows, type PlaylistSheetRow } from './quiz-file';
test('reads an Excel-style workbook: shared strings, rich text, numbers, gaps, sheet order and names', async () => {
const x = deflatedZip({
@@ -142,3 +142,74 @@ test('이지선다 파일: 제목·가수, 조회수 optional (empty = fetched b
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)']);
expect(parseQuizRows(t, guessColumns(t[0]!), 0, 'duel').items.map((i) => [i.title, i.views])).toEqual([['라일락', null]]);
});
test('재생목록으로 엑셀 만들기: kept songs with 비고, unplayable / missing / repeated videos on 빠진 곡, read back by 파일로 만들기', async () => {
const row = (p: Partial<PlaylistSheetRow> & { n: number }): PlaylistSheetRow => ({
source: { title: `원래 ${p.n}`, artist: '채널' },
title: `곡 ${p.n}`,
artist: `가수 ${p.n}`,
durationSec: 200,
videoId: null,
status: 'video',
note: '',
...p,
});
const sheets = playlistSheets([
row({ n: 1, videoId: 'goodday0001', status: 'db', note: '서버 DB 곡 (플레이리스트 영상 사용)', title: '좋은 날', artist: '아이유', durationSec: 230 }),
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 }),
]);
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, '유튜브 뮤직에서 찾음'],
]);
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 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(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],
]);
}
});
test('시작·하이라이트가 빈 곡: 자동 (start 0 + highlight worked out) or 처음부터 (0 / 0); written values are kept either way', () => {
const rows = [
['링크', '정답', '시작(초)', '하이라이트(초)', '길이'],
['iIIjS6yDMQo', '빈 곡', '', '', '3:20'],
['x0-xFqvJ-U8', '하이라이트만', '', '1:05', ''],
['Es6JbQQE79g', '시작만', '12', '', 'abc'],
];
const cols = guessColumns(rows[0]!);
const pos = (blank: 'auto' | 'start') => parseQuizRows(rows, cols, 0, 'normal', blank).items.map((i) => [i.auto, i.startSec, i.highlightSec, i.durationSec]);
expect(pos('auto')).toEqual([
[true, null, null, 200],
[false, 0, 65, null],
[false, 12, null, null],
]);
expect(pos('start')).toEqual([
[false, 0, 0, 200],
[false, 0, 65, null],
[false, 12, null, null],
]);
});