fix(flags): limit challenge requests to country flags

This commit is contained in:
Tommaso Casaburi
2026-06-08 15:43:12 +07:00
parent 6c660c01cd
commit 32dbabb7c7
6 changed files with 17 additions and 19 deletions
@@ -126,17 +126,18 @@ describe('comment-flag-selection', () => {
expect(getCommentFlagRequestFromSelection('none')).toBeUndefined();
});
it('publishes selected flags as signed comment flairs and challenge answers', () => {
it('publishes geographic flags as challenge-backed comment flairs', () => {
expect(getCommentFlagPublishOptionsFromSelection('country:auto')).toEqual({
challengeRequest: {
challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'],
},
flairs: [{ type: 'country', code: 'auto', text: 'flag:country:auto' }],
});
});
it('publishes board-choice flags as regular comment flairs without a challenge request', () => {
expect(getCommentFlagPublishOptionsFromSelection('pony:AJ')).toEqual({
challengeRequest: {
challengeAnswers: ['bitsocial-flags:5chan:flag:pony:AJ'],
},
challengeRequest: undefined,
flairs: [{ type: 'pony', code: 'AJ', text: 'flag:pony:AJ' }],
});
});
+6 -3
View File
@@ -133,9 +133,12 @@ export const getCommentFlagPublishOptionsFromSelection = (value: string | undefi
const flag = getCommentFlagRequestFromSelection(value);
return flag
? {
challengeRequest: {
challengeAnswers: [`${FLAG_CHALLENGE_ANSWER_PREFIX}${flag.text}`],
},
challengeRequest:
flag.type === 'country'
? {
challengeAnswers: [`${FLAG_CHALLENGE_ANSWER_PREFIX}${flag.text}`],
}
: undefined,
flairs: [flag],
}
: {