[#69] added secret link for calendars (#284)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
Co-authored-by: Benoit TELLIER <btellier@linagora.com>
This commit is contained in:
Camille Moussu
2025-11-07 08:30:47 +01:00
committed by GitHub
parent 0647be551f
commit daed6d97ed
6 changed files with 187 additions and 22 deletions
@@ -4,6 +4,7 @@ import {
addSharedCalendar,
getCalendar,
getCalendars,
getSecretLink,
postCalendar,
proppatchCalendar,
removeCalendar,
@@ -114,6 +115,40 @@ describe("Calendar API", () => {
});
});
it("get secret link ", async () => {
const calLink = "/calendars/calId.json";
(api.get as jest.Mock).mockReturnValue({
json: jest.fn().mockResolvedValue("link"),
});
const noreset = await getSecretLink(calLink, false);
expect(api.get).toHaveBeenCalledWith(
`calendar/api${calLink}/secret-link?shouldResetLink=false`,
{
headers: {
Accept: "application/json, text/plain, */*",
},
}
);
});
it("get secret link ", async () => {
const calLink = "/calendars/calId.json";
(api.get as jest.Mock).mockReturnValue({
json: jest.fn().mockResolvedValue("link"),
});
const reset = await getSecretLink(calLink, true);
expect(api.get).toHaveBeenCalledWith(
`calendar/api${calLink}/secret-link?shouldResetLink=true`,
{
headers: {
Accept: "application/json, text/plain, */*",
},
}
);
});
it("When adding a sharedCal with #default as a name a new name is sent to the back", async () => {
const mockApiPost = jest.spyOn(api, "post");
@@ -3,6 +3,11 @@ import CalendarPopover from "../../../src/components/Calendar/CalendarModal";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import { Calendars } from "../../../src/features/Calendars/CalendarTypes";
import { getSecretLink } from "../../../src/features/Calendars/CalendarApi";
jest.mock("../../../src/features/Calendars/CalendarApi", () => ({
getSecretLink: jest.fn(),
}));
describe("CalendarPopover", () => {
const mockOnClose = jest.fn();
@@ -308,6 +313,9 @@ describe("CalendarPopover - Tabs Scenarios", () => {
Object.assign(navigator, {
clipboard: { writeText: jest.fn() },
});
(getSecretLink as jest.Mock).mockResolvedValue({
secretLink: "https://example.org/secret/initial",
});
renderWithProviders(
<CalendarPopover
@@ -326,7 +334,7 @@ describe("CalendarPopover - Tabs Scenarios", () => {
expect(input).toHaveValue("https://cal.example.org/calendars/user1/cal1");
// Click copy button (find button containing ContentCopyIcon)
const copyIcon = screen.getByTestId("ContentCopyIcon");
const copyIcon = screen.getAllByTestId("ContentCopyIcon")[0];
const copyButton = copyIcon.closest("button");
if (copyButton) {
fireEvent.click(copyButton);
@@ -433,4 +441,46 @@ describe("CalendarPopover - Tabs Scenarios", () => {
expect(importButton).toBeDisabled();
});
});
it("fetches and resets the secret link", async () => {
(window as any).CALENDAR_BASE_URL = "https://cal.example.org";
(getSecretLink as jest.Mock)
.mockResolvedValueOnce({
secretLink: "https://example.org/secret/initial",
})
.mockResolvedValueOnce({
secretLink: "https://example.org/secret/new",
});
renderWithProviders(
<CalendarPopover
open={true}
onClose={mockOnClose}
calendar={existingCalendar}
/>,
{ user: baseUser }
);
fireEvent.click(screen.getByRole("tab", { name: /Access/i }));
await waitFor(() =>
expect(
screen.getByDisplayValue("https://example.org/secret/initial")
).toBeInTheDocument()
);
fireEvent.click(screen.getByRole("button", { name: /reset/i }));
await waitFor(() =>
expect(
screen.getByDisplayValue("https://example.org/secret/new")
).toBeInTheDocument()
);
expect(getSecretLink).toHaveBeenCalledWith(
existingCalendar.link.replace(".json", ""),
true
);
});
});