관리자 편집 보호: 자동 매칭은 관리자가 정한 영상을 덮어쓰지 않음(쓰기 시점 조건·실제 갱신만 집계), 다시 가져와도 관리자가 정한 장르(빈 선택 포함) 유지, 안 바꾼 유튜브 주소는 보내지 않음 + 후보 확정 버튼, 회귀 테스트 3개·e2e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
60
apps/server/src/collector/admin-guard.test.ts
Normal file
60
apps/server/src/collector/admin-guard.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/** Regressions: automatic collectors must never undo an admin's edits (review 2026-10-18). */
|
||||
import { afterEach, expect, test } from 'bun:test';
|
||||
import { openDb } from '../db';
|
||||
import { Catalog } from './catalog';
|
||||
import { matchYoutube } from './match-youtube';
|
||||
import { updateSong } from '../songs/store';
|
||||
import { TEST_SUPERADMINS, api, boot, discordLogin, tempDbPath } from '../test-utils';
|
||||
|
||||
test('an admin URL saved while the matcher is searching is not overwritten', async () => {
|
||||
const db = openDb(tempDbPath());
|
||||
const [id] = new Catalog(db).upsert({ title: 'Love wins all', artists: [{ name: '아이유' }], durationSec: 272, source: 't', ref: '1' });
|
||||
const stats = await matchYoutube(
|
||||
db,
|
||||
{
|
||||
searchSongs: async () => {
|
||||
// the admin saves a video while the search is in flight
|
||||
updateSong(db, id, { youtubeId: 'ADMINvideo1' }, { author: 'IU - Topic', title: 'Love wins all' });
|
||||
return [{ videoId: 'Wu5FY8J6P8Q', title: 'Love wins all', artists: '아이유', album: null, durationSec: 272 }];
|
||||
},
|
||||
},
|
||||
{ delayMs: 0 },
|
||||
async () => ({ state: 'ok', author: 'auto', title: 'auto' }),
|
||||
);
|
||||
const row = db.query<{ youtube_id: string; youtube_source: string }, [number]>('SELECT youtube_id, youtube_source FROM songs WHERE id = ?').get(id)!;
|
||||
expect(row).toEqual({ youtube_id: 'ADMINvideo1', youtube_source: 'admin' });
|
||||
expect(stats.matched).toBe(0);
|
||||
});
|
||||
|
||||
test('re-import does not bring back genres the admin removed (also an empty choice)', () => {
|
||||
const db = openDb(tempDbPath());
|
||||
const c = new Catalog(db);
|
||||
const song = { melonId: 5, title: '광', artists: [{ name: 'SG워너비' }], genres: ['ballad', 'kpop'], source: 'norabose', ref: '5' };
|
||||
const [a] = c.upsert(song);
|
||||
updateSong(db, a, { genres: ['rock'] });
|
||||
c.upsert(song);
|
||||
const genres = (id: number) => db.query<{ genre_id: string }, [number]>('SELECT genre_id FROM song_genres WHERE song_id = ? ORDER BY genre_id').all(id).map((r) => r.genre_id);
|
||||
expect(genres(a)).toEqual(['rock']);
|
||||
updateSong(db, a, { genres: [] });
|
||||
c.upsert(song);
|
||||
expect(genres(a)).toEqual([]);
|
||||
});
|
||||
|
||||
let s: ReturnType<typeof boot> | null = null;
|
||||
afterEach(async () => {
|
||||
await s?.stop();
|
||||
s = null;
|
||||
});
|
||||
|
||||
test('saving only a note on a song without video keeps it in the automatic search', async () => {
|
||||
s = boot({ discordExchange: async (code) => ({ id: code, username: 'u', global_name: '관리', avatar: null }) }, { DISCORD_CLIENT_ID: 'c', DISCORD_CLIENT_SECRET: 's' });
|
||||
const [id] = new Catalog(s.db).upsert({ title: '없는영상', artists: [{ name: '누구' }], source: 't', ref: '1' });
|
||||
const sa = await discordLogin(s.base, TEST_SUPERADMINS[0]);
|
||||
// what the editor used to send for a song with no video: youtube: null alongside the note
|
||||
const r = await api(s.base, `/api/admin/songs/${id}`, { method: 'PATCH', cookie: sa.cookie, body: JSON.stringify({ note: '메모', youtube: null }) });
|
||||
expect(r.res.status).toBe(200);
|
||||
expect(r.body.song.youtube_source).toBeNull();
|
||||
let searches = 0;
|
||||
await matchYoutube(s.db, { searchSongs: async () => (searches++, []) }, { delayMs: 0 });
|
||||
expect(searches).toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user