mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(feed): support strict community refs and safer domain publishing
This commit is contained in:
@@ -13,6 +13,7 @@ const testState = vi.hoisted(() => ({
|
||||
abandonPublishMock: vi.fn(async () => undefined),
|
||||
index: 12,
|
||||
lastPublishOptions: undefined as Record<string, any> | undefined,
|
||||
publishAuthorBlockedReason: undefined as 'resolving' | 'unresolved' | 'mismatch' | undefined,
|
||||
publishCommentMock: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -27,6 +28,14 @@ vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('../use-publish-author-domain-guard', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
blockedReason: testState.publishAuthorBlockedReason,
|
||||
}),
|
||||
getPublishAuthorDomainErrorMessage: (reason: string) => `blocked:${reason}`,
|
||||
}));
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let latestValue: ReturnType<typeof usePublishPost>;
|
||||
let root: Root;
|
||||
@@ -47,6 +56,7 @@ describe('usePublishPost', () => {
|
||||
vi.clearAllMocks();
|
||||
testState.index = 12;
|
||||
testState.lastPublishOptions = undefined;
|
||||
testState.publishAuthorBlockedReason = undefined;
|
||||
useChallengesStore.setState({ challenges: [] });
|
||||
usePublishPostStore.getState().resetPublishPostStore();
|
||||
|
||||
@@ -73,7 +83,7 @@ describe('usePublishPost', () => {
|
||||
});
|
||||
|
||||
expect(latestValue.postIndex).toBe(12);
|
||||
expect(latestValue.publishPost).toBe(testState.publishCommentMock);
|
||||
expect(typeof latestValue.publishPost).toBe('function');
|
||||
expect(latestValue.publishPostOptions).toMatchObject({
|
||||
author: { displayName: 'Alice' },
|
||||
communityAddress: 'music.eth',
|
||||
@@ -116,4 +126,16 @@ describe('usePublishPost', () => {
|
||||
|
||||
expect(latestValue.publishPostOptions).toEqual({});
|
||||
});
|
||||
|
||||
it('blocks publish when the active account address is a domain that is not verified yet', async () => {
|
||||
testState.publishAuthorBlockedReason = 'unresolved';
|
||||
renderHook();
|
||||
|
||||
await act(async () => {
|
||||
latestValue.publishPost();
|
||||
});
|
||||
|
||||
expect(latestValue.publishPostError).toBe('blocked:unresolved');
|
||||
expect(testState.publishCommentMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ const testState = vi.hoisted(() => ({
|
||||
directories: [] as Array<Record<string, unknown>>,
|
||||
index: 7,
|
||||
lastPublishOptions: undefined as Record<string, any> | undefined,
|
||||
publishAuthorBlockedReason: undefined as 'resolving' | 'unresolved' | 'mismatch' | undefined,
|
||||
publishCommentMock: vi.fn(),
|
||||
resolveExternalQuoteTargetMock: vi.fn(),
|
||||
}));
|
||||
@@ -46,6 +47,14 @@ vi.mock('../../lib/utils/external-quote-resolver', () => ({
|
||||
resolveExternalQuoteTarget: (...args: any[]) => testState.resolveExternalQuoteTargetMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock('../use-publish-author-domain-guard', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
blockedReason: testState.publishAuthorBlockedReason,
|
||||
}),
|
||||
getPublishAuthorDomainErrorMessage: (reason: string) => `blocked:${reason}`,
|
||||
}));
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let latestValue: ReturnType<typeof usePublishReply>;
|
||||
let root: Root;
|
||||
@@ -68,6 +77,7 @@ describe('usePublishReply', () => {
|
||||
testState.directories = [];
|
||||
testState.index = 7;
|
||||
testState.lastPublishOptions = undefined;
|
||||
testState.publishAuthorBlockedReason = undefined;
|
||||
useChallengesStore.setState({ challenges: [] });
|
||||
usePostNumberStore.setState({ cidToNumber: {}, numberToCid: { 'music.eth': { 12: 'quoted-cid' } } });
|
||||
usePublishReplyStore.setState({
|
||||
@@ -175,6 +185,18 @@ describe('usePublishReply', () => {
|
||||
expect(testState.publishCommentMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('blocks publish when the active account address is a domain that is not verified yet', async () => {
|
||||
testState.publishAuthorBlockedReason = 'unresolved';
|
||||
renderHook();
|
||||
|
||||
await act(async () => {
|
||||
await latestValue.publishReply();
|
||||
});
|
||||
|
||||
expect(latestValue.publishReplyError).toBe('blocked:unresolved');
|
||||
expect(testState.publishCommentMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('queues reply challenges and clears the scoped reply store on reset', async () => {
|
||||
await act(async () => {
|
||||
latestValue.setPublishReplyOptions({
|
||||
|
||||
Reference in New Issue
Block a user