Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -11,7 +11,7 @@ const mockWindow = {
|
||||
VIDEO_CONFERENCE_BASE_URL: "https://meet.linagora.com",
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error : Mock window object for Node.js environment
|
||||
global.window = mockWindow;
|
||||
|
||||
describe("videoConferenceUtils", () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ const RETRY_CONFIG = {
|
||||
maxDelay: 120000,
|
||||
};
|
||||
export const api = ky.extend({
|
||||
prefixUrl: (window as any).CALENDAR_BASE_URL,
|
||||
prefixUrl: window.CALENDAR_BASE_URL,
|
||||
retry: {
|
||||
limit: RETRY_CONFIG.maxRetries,
|
||||
backoffLimit: RETRY_CONFIG.maxDelay,
|
||||
@@ -90,7 +90,7 @@ export function isValidUrl(string?: string) {
|
||||
|
||||
try {
|
||||
url = new URL(string ?? "");
|
||||
} catch (_) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return url;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { AsyncThunkResult } from "@/features/Calendars/types/AsyncThunkResult";
|
||||
|
||||
export async function assertThunkSuccess(result: unknown): Promise<void> {
|
||||
const typed = result as AsyncThunkResult;
|
||||
if (typed?.type?.endsWith("/rejected")) {
|
||||
throw new Error(
|
||||
typed.error?.message || typed.payload?.message || "API call failed"
|
||||
);
|
||||
}
|
||||
if (typeof typed.unwrap === "function") {
|
||||
await typed.unwrap();
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -1,9 +1,26 @@
|
||||
import { RejectedError } from "@/features/Calendars/types/RejectedError";
|
||||
|
||||
export function formatReduxError(error: unknown): string {
|
||||
if (!error) return "Unknown error";
|
||||
|
||||
if (typeof error === "string") return error;
|
||||
if (typeof error === "object") {
|
||||
const err = error as any;
|
||||
if (err?.message) return err.message;
|
||||
|
||||
if (typeof error === "object" && error !== null) {
|
||||
if (
|
||||
"message" in error &&
|
||||
typeof (error as { message: unknown }).message === "string"
|
||||
) {
|
||||
return (error as { message: string }).message;
|
||||
}
|
||||
}
|
||||
|
||||
return "Unexpected error occurred";
|
||||
}
|
||||
|
||||
export function toRejectedError(err: unknown): RejectedError {
|
||||
const status =
|
||||
typeof err === "object" && err !== null && "response" in err
|
||||
? (err as { response?: { status?: number } }).response?.status
|
||||
: undefined;
|
||||
return { message: formatReduxError(err), status };
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ export function registerTimezones() {
|
||||
}
|
||||
}
|
||||
|
||||
function buildTimezone(tzid: string, ics: string): any {
|
||||
function buildTimezone(tzid: string, ics: string): ICAL.Timezone {
|
||||
return (
|
||||
ICAL.TimezoneService.get(tzid) ||
|
||||
new ICAL.Timezone(new ICAL.Component(ICAL.parse(ics)))
|
||||
);
|
||||
}
|
||||
|
||||
function findTimezone(tzid: string): any {
|
||||
function findTimezone(tzid: string): ICAL.Timezone {
|
||||
if (TIMEZONES.zones[tzid]) {
|
||||
return buildTimezone(tzid, TIMEZONES.zones[tzid].ics);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ export function generateMeetingId(): string {
|
||||
*/
|
||||
export function generateMeetingLink(baseUrl?: string): string {
|
||||
const base =
|
||||
baseUrl ||
|
||||
(window as any).VIDEO_CONFERENCE_BASE_URL ||
|
||||
"https://meet.linagora.com";
|
||||
baseUrl || window.VIDEO_CONFERENCE_BASE_URL || "https://meet.linagora.com";
|
||||
const meetingId = generateMeetingId();
|
||||
return `${base}/${meetingId}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user