このコミットが含まれているのは:
2026-06-14 05:31:00 +09:00
コミット 791b52e894
5個のファイルの変更413行の追加13行の削除
+90
ファイルの表示
@@ -4,6 +4,7 @@ import { apiPost } from '@/lib/api'
import {
buildGekanatorQuestions,
expectedAnswerForQuestion,
questionIdForCondition,
restoreGekanatorQuestion,
saveGekanatorExtraQuestionAnswers,
saveGekanatorGame,
@@ -164,6 +165,27 @@ describe('expectedAnswerForQuestion', () => {
expect(expectedAnswerForQuestion(question, post({ id: 1, title: 'short' }))).toBe('no')
})
it('returns yes for matching title-contains questions', () => {
const question: StoredGekanatorQuestion = {
id: 'title:contains:結束バンド',
text: '題名に「結束バンド」が含まれる?',
kind: 'title',
condition: {
type: 'title-contains',
text: '結束バンド',
},
}
expect(expectedAnswerForQuestion(
question,
post({ title: '結束バンドのライブ' }),
)).toBe('yes')
expect(expectedAnswerForQuestion(
question,
post({ title: '後藤ひとりの休日' }),
)).toBe('no')
})
})
describe('restoreGekanatorQuestion', () => {
@@ -248,6 +270,21 @@ describe('restoreGekanatorQuestion', () => {
expect(question.test(post({ title: 'x'.repeat(20) }))).toBe(false)
expect(question.test(post({ title: 'x'.repeat(21) }))).toBe(true)
})
it('restores title-contains questions with a title matcher', () => {
const question = restoreGekanatorQuestion({
id: 'title:contains:結束バンド',
text: '題名に「結束バンド」が含まれる?',
kind: 'title',
condition: {
type: 'title-contains',
text: '結束バンド',
},
})
expect(question.test(post({ title: '結束バンドのライブ' }))).toBe(true)
expect(question.test(post({ title: '後藤ひとりの休日' }))).toBe(false)
})
})
describe('buildGekanatorQuestions', () => {
@@ -264,6 +301,59 @@ describe('buildGekanatorQuestions', () => {
expect(titleQuestion?.text).toMatch(/^タイトルは \d+ 文字以上\?$/)
expect(titleQuestion?.id).toMatch(/^title:length-at-least:\d+$/)
})
it('builds title-contains questions from repeated title words', () => {
const questions = buildGekanatorQuestions([
post({ id: 1, title: '結束バンド ライブ' }),
post({ id: 2, title: '結束バンド 新曲' }),
post({ id: 3, title: '後藤ひとり 練習' }),
post({ id: 4, title: '伊地知虹夏 練習' }),
])
const titleContainsQuestion = questions.find(question =>
question.condition.type === 'title-contains'
&& question.condition.text === '結束バンド')
expect(titleContainsQuestion).toMatchObject({
id: 'title:contains:結束バンド',
text: '題名に「結束バンド」が含まれる?',
kind: 'title',
source: 'default',
priorityWeight: .96,
})
expect(titleContainsQuestion?.test(post({ title: '結束バンドのライブ' }))).toBe(true)
expect(titleContainsQuestion?.test(post({ title: '廣井きくりのライブ' }))).toBe(false)
})
it('honors question caps and title-contains toggles', () => {
const posts = [
post({ id: 1, title: '結束バンド ライブ' }),
post({ id: 2, title: '結束バンド 新曲' }),
post({ id: 3, title: '後藤ひとり 練習' }),
post({ id: 4, title: '伊地知虹夏 練習' }),
]
const capped = buildGekanatorQuestions(posts, {
titleContainsCap: 1,
totalQuestionCap: 1,
})
const withoutTitleContains = buildGekanatorQuestions(posts, {
includeTitleContains: false,
})
expect(capped).toHaveLength(1)
expect(withoutTitleContains.some(question =>
question.condition.type === 'title-contains')).toBe(false)
})
})
describe('questionIdForCondition', () => {
it('builds stable ids for title-contains questions', () => {
expect(questionIdForCondition({
type: 'title-contains',
text: '結束バンド',
})).toBe('title:contains:結束バンド')
})
})
describe('Gekanator API writers', () => {
+24 -1
ファイルの表示
@@ -145,7 +145,30 @@ describe('recoverCandidatePosts', () => {
expect(recovered?.recoveryStepCount).toBe (1)
expect([...(recovered?.recoveredCandidatePosts.keys () ?? [])])
.toEqual ([8, 7, 6, 5, 4, 3, 2])
.toEqual ([8, 7, 6, 5, 4])
expect(recovered?.recoveredCandidatePosts.get (7)).toBe (2)
})
it('does not add posts when recovered and eligible candidates already hit the target', () => {
const posts = Array.from ({ length: 10 }, (_value, index) => post (index + 1))
const scores = new Map (posts.map (candidate => [candidate.id, candidate.id]))
const recovered = recoverCandidatePosts ({
posts,
scores,
rejectedPostIds: new Set (),
recoveredCandidatePosts: new Map ([
[1, 1],
[2, 1],
[3, 1],
]),
eligiblePostIds: new Set ([4, 5, 6]),
answerCountAtRecovery: 2,
recoveryStepCount: 0,
})
expect(recovered?.recoveryStepCount).toBe (1)
expect([...(recovered?.recoveredCandidatePosts.keys () ?? [])])
.toEqual ([1, 2, 3])
})
})