Keep shared Rule files reachable, and say when a privacy change does not save.
This commit is contained in:
1 parent
b6795c1f18
commit
63ba21c614
9 files changed
+148
-16
No files matched your search
@@ -8,8 +8,15 @@ import {
|
||||
} from "../../utils/test-utils";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import Share from "../../../app/components/modals/Share";
|
||||
import { patchRuleShare } from "../../../lib/create/api";
|
||||
import type { RuleShareSettings } from "../../../lib/ruleShareTypes";
|
||||
|
||||
vi.mock("../../../lib/create/api", () => ({
|
||||
patchRuleShare: vi.fn(),
|
||||
fetchRuleShare: vi.fn(),
|
||||
addRuleStakeholder: vi.fn(),
|
||||
}));
|
||||
|
||||
const previewSettings: RuleShareSettings = {
|
||||
visibility: "private",
|
||||
shareSlug: null,
|
||||
@@ -41,9 +48,18 @@ function openShare(overrides: Partial<RuleShareSettings> = {}) {
|
||||
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
const sharedSettings: RuleShareSettings = {
|
||||
...previewSettings,
|
||||
visibility: "shared_by_link",
|
||||
shareSlug: "k7f2-9qxm",
|
||||
shareUrl: "https://communityrule.info/r/k7f2-9qxm",
|
||||
shareUrlDisplay: "communityrule.info/r/k7f2-9qxm",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
writeText.mockReset();
|
||||
writeText.mockResolvedValue(undefined);
|
||||
vi.mocked(patchRuleShare).mockReset();
|
||||
Object.defineProperty(window.navigator, "clipboard", {
|
||||
configurable: true,
|
||||
value: { writeText },
|
||||
@@ -133,6 +149,58 @@ describe("Share modal", () => {
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the link on and says so when turning the Rule private does not save", async () => {
|
||||
vi.mocked(patchRuleShare).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
status: 500,
|
||||
error: "nope",
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<Share
|
||||
isOpen
|
||||
onClose={vi.fn()}
|
||||
ruleId="rule-1"
|
||||
previewSettings={sharedSettings}
|
||||
/>,
|
||||
);
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: /Anyone with the link/i }),
|
||||
);
|
||||
await user.click(
|
||||
await screen.findByRole("option", { name: "Only people you invite" }),
|
||||
);
|
||||
expect(await screen.findByText("That change didn’t save")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Turn off link" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText("Only people you invite can open it."),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the link on and says so when turning the link off does not save", async () => {
|
||||
vi.mocked(patchRuleShare).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
status: 500,
|
||||
error: "nope",
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<Share
|
||||
isOpen
|
||||
onClose={vi.fn()}
|
||||
ruleId="rule-1"
|
||||
previewSettings={sharedSettings}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Turn off link" }));
|
||||
expect(await screen.findByText("That change didn’t save")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByDisplayValue("communityrule.info/r/k7f2-9qxm"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls onClose when Done is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
|
||||
@@ -153,6 +153,27 @@ describe("getReadablePublishedRule", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("lets anonymous readers of a shared Rule through when the caller already has the id", async () => {
|
||||
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||
findUniqueMock.mockResolvedValueOnce(
|
||||
row({
|
||||
visibility: RULE_VISIBILITY.shared_by_link,
|
||||
shareSlug: "k7f2-9qxm",
|
||||
}),
|
||||
);
|
||||
const resolved = await getReadablePublishedRule({
|
||||
idOrSlug: "owned-1",
|
||||
user: null,
|
||||
viaShareSlug: true,
|
||||
lookup: "id",
|
||||
requestPath: "/api/uploads/file-1",
|
||||
});
|
||||
expect(resolved?.rule.id).toBe("owned-1");
|
||||
expect(findUniqueMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { id: "owned-1" } }),
|
||||
);
|
||||
});
|
||||
|
||||
it("lets anonymous readers use the rotating slug", async () => {
|
||||
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||
findUniqueMock.mockResolvedValueOnce(
|
||||
|
||||
@@ -153,7 +153,11 @@ describe("GET /api/uploads/[id]", () => {
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(getReadablePublishedRuleMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ viaShareSlug: true }),
|
||||
expect.objectContaining({
|
||||
idOrSlug: "rule-shared",
|
||||
viaShareSlug: true,
|
||||
lookup: "id",
|
||||
}),
|
||||
);
|
||||
expect(res.headers.get("Cache-Control")).toBe("private, no-store");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user