feat(tag-vocab): NoteRepository — getTopUsedTags + getTagIdByName (#3 v0.2.3)
- getTopUsedTags(limit=20): top-N (count desc, id asc) + kebab-case 필터 + deleted_at 제외 - getTagIdByName(name): COLLATE NOCASE lookup - AI+user source 통합 카운트 (Q1=C 결정) - 단위 +7 cases (정렬, 필터, source 통합, deleted 제외, limit, getTagIdByName) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -652,4 +652,73 @@ describe('NoteRepository — failed retry helpers', () => {
|
||||
expect(job.attempts).toBe(1); // 변화 없음
|
||||
expect(job.nextRunAt).toBe('2026-05-01T12:00:00.000Z');
|
||||
});
|
||||
|
||||
it('getTopUsedTags returns [] when no notes', () => {
|
||||
expect(repo.getTopUsedTags()).toEqual([]);
|
||||
});
|
||||
|
||||
it('getTopUsedTags orders by count desc, id asc tiebreaker', () => {
|
||||
const a = repo.create({ rawText: 'a' }).id;
|
||||
const b = repo.create({ rawText: 'b' }).id;
|
||||
const c = repo.create({ rawText: 'c' }).id;
|
||||
repo.updateAiResult(a, { title: 't', summary: 'a\nb\nc', tags: ['design', 'meeting'], provider: 'p' });
|
||||
repo.updateAiResult(b, { title: 't', summary: 'a\nb\nc', tags: ['design'], provider: 'p' });
|
||||
repo.updateAiResult(c, { title: 't', summary: 'a\nb\nc', tags: ['design', 'meeting', 'qa'], provider: 'p' });
|
||||
// counts: design=3, meeting=2, qa=1
|
||||
expect(repo.getTopUsedTags()).toEqual(['design', 'meeting', 'qa']);
|
||||
});
|
||||
|
||||
it('getTopUsedTags filters non-kebab-case (한글/대문자/공백)', () => {
|
||||
const a = repo.create({ rawText: 'a' }).id;
|
||||
// user route 가 한글/공백 태그 들어올 수 있음 → vocab 에서 제외 검증
|
||||
repo.updateUserAiFields(a, { tags: ['design', '회의', 'Meeting', 'two words', 'api-timeout'] });
|
||||
expect(repo.getTopUsedTags()).toEqual(expect.arrayContaining(['design', 'api-timeout']));
|
||||
expect(repo.getTopUsedTags()).not.toContain('회의');
|
||||
expect(repo.getTopUsedTags()).not.toContain('Meeting');
|
||||
expect(repo.getTopUsedTags()).not.toContain('two words');
|
||||
});
|
||||
|
||||
it('getTopUsedTags counts AI + user sources together', () => {
|
||||
const a = repo.create({ rawText: 'a' }).id;
|
||||
const b = repo.create({ rawText: 'b' }).id;
|
||||
repo.updateAiResult(a, { title: 't', summary: 'x\ny\nz', tags: ['design'], provider: 'p' });
|
||||
repo.updateUserAiFields(b, { tags: ['design'] });
|
||||
// design count 는 AI 1 + user 1 = 2
|
||||
const top = repo.getTopUsedTags();
|
||||
expect(top).toContain('design');
|
||||
});
|
||||
|
||||
it('getTopUsedTags excludes tags from deleted notes', () => {
|
||||
const a = repo.create({ rawText: 'a' }).id;
|
||||
repo.updateAiResult(a, { title: 't', summary: 'x\ny\nz', tags: ['lonely'], provider: 'p' });
|
||||
repo.trash(a, new Date().toISOString());
|
||||
expect(repo.getTopUsedTags()).not.toContain('lonely');
|
||||
});
|
||||
|
||||
it('getTopUsedTags respects LIMIT parameter', () => {
|
||||
const ids: string[] = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const id = repo.create({ rawText: `n${i}` }).id;
|
||||
ids.push(id);
|
||||
repo.updateAiResult(id, {
|
||||
title: 't', summary: 'a\nb\nc',
|
||||
tags: [`tag-${i}`],
|
||||
provider: 'p'
|
||||
});
|
||||
}
|
||||
expect(repo.getTopUsedTags(3)).toHaveLength(3);
|
||||
expect(repo.getTopUsedTags(10)).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('getTagIdByName returns id when present, null when absent', () => {
|
||||
const a = repo.create({ rawText: 'a' }).id;
|
||||
repo.updateAiResult(a, { title: 't', summary: 'a\nb\nc', tags: ['hello'], provider: 'p' });
|
||||
const id = repo.getTagIdByName('hello');
|
||||
expect(typeof id).toBe('number');
|
||||
expect(id).toBeGreaterThan(0);
|
||||
// case-insensitive
|
||||
expect(repo.getTagIdByName('HELLO')).toBe(id);
|
||||
// absent
|
||||
expect(repo.getTagIdByName('nothere')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user