Keep a guest community logo on review and on the published rule.
Sign-in was clearing the staged file before it uploaded, and review only read the server URL, so a chosen logo disappeared after the upload step.
This commit is contained in:
1 parent
2348a9e94f
commit
8212423ec3
19 files changed
+780
-61
No files matched your search
@@ -3,6 +3,9 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import type { CreateFlowState } from "../../../app/(app)/create/types";
|
||||
import { useCreateFlowFinalize } from "../../../app/(app)/create/hooks/useCreateFlowFinalize";
|
||||
import { publishRule, updatePublishedRule } from "../../../lib/create/api";
|
||||
import { buildPublishPayload } from "../../../lib/create/buildPublishPayload";
|
||||
import { stateWithPendingCommunityAvatar } from "../../../lib/create/flushPendingCommunityAvatar";
|
||||
import messages from "../../../messages/en/index";
|
||||
import { writeLastPublishedRule } from "../../../lib/create/lastPublishedRule";
|
||||
import { CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY } from "../../../lib/create/pendingKeepRuleLogin";
|
||||
import {
|
||||
@@ -24,6 +27,13 @@ vi.mock("../../../lib/create/api", () => ({
|
||||
updatePublishedRule: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../../../lib/create/flushPendingCommunityAvatar", () => ({
|
||||
stateWithPendingCommunityAvatar: vi.fn(async (state: CreateFlowState) => ({
|
||||
ok: true as const,
|
||||
state,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../../../lib/create/lastPublishedRule", () => ({
|
||||
writeLastPublishedRule: vi.fn(),
|
||||
}));
|
||||
@@ -41,6 +51,10 @@ describe("useCreateFlowFinalize", () => {
|
||||
vi.mocked(publishRule).mockReset();
|
||||
vi.mocked(updatePublishedRule).mockReset();
|
||||
vi.mocked(writeLastPublishedRule).mockReset();
|
||||
vi.mocked(stateWithPendingCommunityAvatar).mockReset();
|
||||
vi.mocked(stateWithPendingCommunityAvatar).mockImplementation(
|
||||
async (state) => ({ ok: true as const, state }),
|
||||
);
|
||||
router.push.mockReset();
|
||||
updateState.mockReset();
|
||||
openLogin.mockReset();
|
||||
@@ -148,6 +162,82 @@ describe("useCreateFlowFinalize", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("publishes a guest logo that was only staged in the browser", async () => {
|
||||
vi.mocked(publishRule).mockResolvedValue({
|
||||
ok: true,
|
||||
id: "guest-rule-id",
|
||||
title: "Published title",
|
||||
});
|
||||
vi.mocked(stateWithPendingCommunityAvatar).mockResolvedValue({
|
||||
ok: true,
|
||||
state: {
|
||||
communityAvatarFileName: "logo.png",
|
||||
communityAvatarUrl: "/api/uploads/guest-logo",
|
||||
},
|
||||
});
|
||||
vi.mocked(buildPublishPayload).mockImplementationOnce((draft) => ({
|
||||
ok: true as const,
|
||||
title: "Published title",
|
||||
summary: "Published summary",
|
||||
document: {
|
||||
communityAvatarUrl: draft.communityAvatarUrl,
|
||||
},
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useCreateFlowFinalize({
|
||||
state: { communityAvatarFileName: "logo.png" },
|
||||
router,
|
||||
openLogin,
|
||||
updateState,
|
||||
loginReturnPath: "/create/final-review",
|
||||
sessionUser: null,
|
||||
onGuestPublished,
|
||||
}),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await result.current.finalize();
|
||||
});
|
||||
|
||||
expect(publishRule).toHaveBeenCalledWith({
|
||||
title: "Published title",
|
||||
summary: "Published summary",
|
||||
document: { communityAvatarUrl: "/api/uploads/guest-logo" },
|
||||
});
|
||||
expect(updateState).toHaveBeenCalledWith({
|
||||
communityAvatarUrl: "/api/uploads/guest-logo",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not publish when the staged logo fails to upload", async () => {
|
||||
vi.mocked(stateWithPendingCommunityAvatar).mockResolvedValue({
|
||||
ok: false,
|
||||
reason: "upload_failed",
|
||||
});
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useCreateFlowFinalize({
|
||||
state: { communityAvatarFileName: "logo.png" },
|
||||
router,
|
||||
openLogin,
|
||||
updateState,
|
||||
loginReturnPath: "/create/final-review",
|
||||
sessionUser: null,
|
||||
}),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await result.current.finalize();
|
||||
});
|
||||
|
||||
expect(publishRule).not.toHaveBeenCalled();
|
||||
expect(result.current.publishBannerMessage).toBe(
|
||||
messages.create.upload.errors.generic,
|
||||
);
|
||||
expect(result.current.isPublishing).toBe(false);
|
||||
});
|
||||
|
||||
it("hints to claim later when a guest publishes without stakeholder emails", async () => {
|
||||
vi.mocked(publishRule).mockResolvedValue({
|
||||
ok: true,
|
||||
|
||||
Reference in new issue
Block a user