mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(mod-queue): preserve pending reject state after refresh
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { approvePendingCommentModeration, isPendingApprovalAwaiting, isPendingApprovalRejected, rejectPendingCommentModeration } from '../pending-approval-moderation';
|
||||
|
||||
describe('pending approval moderation utils', () => {
|
||||
it('publishes approval with approved=true', () => {
|
||||
expect(approvePendingCommentModeration).toEqual({ approved: true });
|
||||
});
|
||||
|
||||
it('publishes rejection with approved=false and no removed flag', () => {
|
||||
expect(rejectPendingCommentModeration).toEqual({ approved: false });
|
||||
expect('removed' in rejectPendingCommentModeration).toBe(false);
|
||||
});
|
||||
|
||||
it('treats pending approved=false as rejected for display', () => {
|
||||
expect(isPendingApprovalRejected({ pendingApproval: true, approved: false })).toBe(true);
|
||||
expect(isPendingApprovalAwaiting({ pendingApproval: true, approved: false })).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps pending approvals awaiting when no decision has been made', () => {
|
||||
expect(isPendingApprovalRejected({ pendingApproval: true })).toBe(false);
|
||||
expect(isPendingApprovalAwaiting({ pendingApproval: true })).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
export const approvePendingCommentModeration = { approved: true } as const;
|
||||
|
||||
// plebbit-js clears pendingApproval only when rejection is published as approved:false.
|
||||
// Sending removed:true marks the comment removed but can leave it in the mod queue.
|
||||
export const rejectPendingCommentModeration = { approved: false } as const;
|
||||
|
||||
type PendingApprovalDisplayState = {
|
||||
approved?: boolean;
|
||||
removed?: boolean;
|
||||
pendingApproval?: boolean;
|
||||
};
|
||||
|
||||
export const isPendingApprovalRejected = (comment?: PendingApprovalDisplayState) =>
|
||||
comment?.removed === true || (comment?.pendingApproval === true && comment?.approved === false);
|
||||
|
||||
export const isPendingApprovalAwaiting = (comment?: PendingApprovalDisplayState) =>
|
||||
comment?.pendingApproval === true && comment?.approved !== true && !isPendingApprovalRejected(comment);
|
||||
Reference in New Issue
Block a user