Reviewed-on: #368 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #368 でマージされました.
このコミットが含まれているのは:
@@ -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', () => {
|
||||
|
||||
新しい課題から参照
ユーザをブロックする