Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe("WebSocket Server", () => {
...userMetadata,
google: {
hasRefreshToken: false,
connectionStatus: "not_connected",
connectionStatus: "NOT_CONNECTED",
syncStatus: "NONE",
},
},
Expand Down
16 changes: 8 additions & 8 deletions packages/backend/src/user/services/user-metadata.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ describe("UserMetadataService", () => {
expect(metadata.sync?.importGCal).toBe("RESTART");
});

it("returns not_connected when the user never connected Google", async () => {
it("returns NOT_CONNECTED when the user never connected Google", async () => {
const user = await UserDriver.createUser({ withGoogle: false });
const userId = user._id.toString();

const metadata = await driver.fetchUserMetadata(userId);

expect(metadata.google).toMatchObject({
hasRefreshToken: false,
connectionStatus: "not_connected",
connectionStatus: "NOT_CONNECTED",
syncStatus: "NONE",
});
});
Expand All @@ -81,7 +81,7 @@ describe("UserMetadataService", () => {

expect(metadata.google).toMatchObject({
hasRefreshToken: false,
connectionStatus: "reconnect_required",
connectionStatus: "RECONNECT_REQUIRED",
syncStatus: "NONE",
});
});
Expand All @@ -94,7 +94,7 @@ describe("UserMetadataService", () => {

expect(metadata.google).toMatchObject({
hasRefreshToken: true,
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "HEALTHY",
});
});
Expand All @@ -111,7 +111,7 @@ describe("UserMetadataService", () => {

expect(metadata.google).toMatchObject({
hasRefreshToken: true,
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "HEALTHY",
});

Expand All @@ -129,7 +129,7 @@ describe("UserMetadataService", () => {

expect(metadata.google).toMatchObject({
hasRefreshToken: true,
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "ATTENTION",
});
expect(restartSpy).not.toHaveBeenCalled();
Expand All @@ -150,7 +150,7 @@ describe("UserMetadataService", () => {

expect(metadata.google).toMatchObject({
hasRefreshToken: true,
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "ATTENTION",
});
});
Expand All @@ -170,7 +170,7 @@ describe("UserMetadataService", () => {
const metadata = await driver.fetchUserMetadata(userId);

expect(metadata.google).toMatchObject({
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "REPAIRING",
});
expect(restartSpy).not.toHaveBeenCalled();
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/user/services/user-metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class UserMetadataService {
const googleId = user?.google?.googleId;
const hasRefreshToken = Boolean(user?.google?.gRefreshToken);

if (!googleId) return "not_connected";
if (!hasRefreshToken) return "reconnect_required";
if (!googleId) return "NOT_CONNECTED";
if (!hasRefreshToken) return "RECONNECT_REQUIRED";

return "connected";
return "CONNECTED";
}

private async isGoogleSyncHealthy(userId: string): Promise<boolean> {
Expand Down Expand Up @@ -105,7 +105,7 @@ class UserMetadataService {
const hasRefreshToken = Boolean(user?.google?.gRefreshToken);
const connectionStatus = this.getGoogleConnectionStatus(user);

if (connectionStatus !== "connected") {
if (connectionStatus !== "CONNECTED") {
return {
hasRefreshToken,
connectionStatus,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/user.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export interface Schema_User {

type SyncStatus = "IMPORTING" | "ERRORED" | "COMPLETED" | "RESTART" | null;
export type GoogleConnectionStatus =
| "not_connected"
| "connected"
| "reconnect_required";
| "NOT_CONNECTED"
| "CONNECTED"
| "RECONNECT_REQUIRED";
export type GoogleSyncStatus = "HEALTHY" | "REPAIRING" | "ATTENTION" | "NONE";

export interface UserMetadata extends SupertokensUserMetadata.JSONObject {
Expand Down
16 changes: 8 additions & 8 deletions packages/web/src/auth/hooks/oauth/useConnectGoogle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "not_connected",
connectionStatus: "NOT_CONNECTED",
syncStatus: "NONE",
};
}
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "HEALTHY",
};
}
Expand All @@ -145,15 +145,15 @@ describe("useConnectGoogle", () => {
);
expect(result.current.commandAction.isDisabled).toBe(true);
expect(result.current.commandAction.onSelect).toBeUndefined();
expect(result.current.sidebarStatus.icon).toBe("CheckCircleIcon");
expect(result.current.sidebarStatus.icon).toBe("LinkIcon");
expect(result.current.sidebarStatus.isDisabled).toBe(true);
});

it("returns reconnect state when refresh token is missing", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "reconnect_required",
connectionStatus: "RECONNECT_REQUIRED",
syncStatus: "NONE",
};
}
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "REPAIRING",
};
}
Expand Down Expand Up @@ -224,7 +224,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "ATTENTION",
};
}
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "not_connected",
connectionStatus: "NOT_CONNECTED",
syncStatus: "NONE",
};
}
Expand Down Expand Up @@ -312,7 +312,7 @@ describe("useConnectGoogle", () => {
mockUseAppSelector.mockImplementation((selector) => {
if (selector === selectGoogleMetadata) {
return {
connectionStatus: "reconnect_required",
connectionStatus: "RECONNECT_REQUIRED",
syncStatus: "NONE",
};
}
Expand Down
26 changes: 13 additions & 13 deletions packages/web/src/auth/hooks/oauth/useConnectGoogle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";

type GoogleUiState =
| "checking"
| "not_connected"
| "reconnect_required"
| "NOT_CONNECTED"
| "RECONNECT_REQUIRED"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent casing within GoogleUiState type values

Low Severity

The GoogleUiState type now mixes UPPER_CASE ("NOT_CONNECTED", "RECONNECT_REQUIRED") with snake_case ("checking", "connected_healthy", "connected_repairing", "connected_attention"). Before this PR, all values were consistently snake_case. In a PR aiming for casing consistency, this introduces a new inconsistency within a single union type.

Fix in Cursor Fix in Web

| "connected_healthy"
| "connected_repairing"
| "connected_attention";

type SidebarStatusIcon =
| "CloudArrowUpIcon"
| "LinkBreakIcon"
| "CheckCircleIcon"
| "LinkIcon"
| "SpinnerIcon"
| "CloudWarningIcon";

Expand Down Expand Up @@ -63,8 +63,8 @@ const getGoogleUiState = ({
isImporting: boolean;
isCheckingStatus: boolean;
}): GoogleUiState => {
if (connectionStatus === "reconnect_required") {
return "reconnect_required";
if (connectionStatus === "RECONNECT_REQUIRED") {
return "RECONNECT_REQUIRED";
}

if (isImporting) {
Expand All @@ -75,19 +75,19 @@ const getGoogleUiState = ({
return "checking";
}

if (connectionStatus === "connected" && syncStatus === "REPAIRING") {
if (connectionStatus === "CONNECTED" && syncStatus === "REPAIRING") {
return "connected_repairing";
}

if (connectionStatus === "connected" && syncStatus === "ATTENTION") {
if (connectionStatus === "CONNECTED" && syncStatus === "ATTENTION") {
return "connected_attention";
}

if (connectionStatus === "connected") {
if (connectionStatus === "CONNECTED") {
return "connected_healthy";
}

return "not_connected";
return "NOT_CONNECTED";
};

const getGoogleUiConfig = (
Expand All @@ -110,7 +110,7 @@ const getGoogleUiConfig = (
isDisabled: true,
},
};
case "not_connected":
case "NOT_CONNECTED":
return {
commandAction: {
label: "Connect Google Calendar",
Expand All @@ -125,7 +125,7 @@ const getGoogleUiConfig = (
onSelect: onConnectGoogle,
},
};
case "reconnect_required":
case "RECONNECT_REQUIRED":
return {
commandAction: {
label: "Reconnect Google Calendar",
Expand Down Expand Up @@ -176,7 +176,7 @@ const getGoogleUiConfig = (
isDisabled: true,
},
sidebarStatus: {
icon: "CheckCircleIcon",
icon: "LinkIcon",
tooltip: "Google Calendar connected.",
isDisabled: true,
},
Expand All @@ -199,7 +199,7 @@ export const useConnectGoogle = () => {
state: RootState,
) => RootState["sync"]["importGCal"],
);
const connectionStatus = googleMetadata?.connectionStatus ?? "not_connected";
const connectionStatus = googleMetadata?.connectionStatus ?? "NOT_CONNECTED";
const syncStatus = googleMetadata?.syncStatus ?? "NONE";
const { login } = useGoogleAuth();

Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/auth/session/user-metadata.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jest.mock("@web/store", () => ({
}));

describe("refreshUserMetadata", () => {
const api = UserApi as {
const api = UserApi as unknown as {
getMetadata: jest.MockedFunction<typeof UserApi.getMetadata>;
};
const getDispatchMock = () =>
Expand All @@ -29,7 +29,7 @@ describe("refreshUserMetadata", () => {
it("loads metadata into the store", async () => {
const metadata = {
google: {
connectionStatus: "connected" as const,
connectionStatus: "CONNECTED" as const,
syncStatus: "HEALTHY" as const,
},
};
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/socket/hooks/useGcalSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe("useGcalSync", () => {

metadataHandler?.({
sync: { importGCal: "RESTART" },
google: { connectionStatus: "connected" },
google: { connectionStatus: "CONNECTED" },
});

expect(mockDispatch).toHaveBeenCalledWith(
Expand All @@ -243,7 +243,7 @@ describe("useGcalSync", () => {

metadataHandler?.({
sync: { importGCal: "RESTART" },
google: { connectionStatus: "reconnect_required" },
google: { connectionStatus: "RECONNECT_REQUIRED" },
});

expect(importGCalSlice.actions.request).not.toHaveBeenCalled();
Expand All @@ -261,7 +261,7 @@ describe("useGcalSync", () => {

metadataHandler?.({
sync: { importGCal: "ERRORED" },
google: { connectionStatus: "connected", syncStatus: "ATTENTION" },
google: { connectionStatus: "CONNECTED", syncStatus: "ATTENTION" },
});

expect(importGCalSlice.actions.request).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/socket/hooks/useGcalSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const useGcalSync = () => {
const connectionStatus = metadata.google?.connectionStatus;
const isBackendImporting = importStatus === "IMPORTING";
const shouldAutoImport =
importStatus === "RESTART" && connectionStatus === "connected";
importStatus === "RESTART" && connectionStatus === "CONNECTED";

dispatch(userMetadataSlice.actions.set(metadata));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("SidebarIconRow", () => {
userMetadata: {
current: {
google: {
connectionStatus: "not_connected",
connectionStatus: "NOT_CONNECTED",
syncStatus: "NONE",
},
},
Expand All @@ -82,7 +82,7 @@ describe("SidebarIconRow", () => {
userMetadata: {
current: {
google: {
connectionStatus: "reconnect_required",
connectionStatus: "RECONNECT_REQUIRED",
syncStatus: "NONE",
},
},
Expand All @@ -106,7 +106,7 @@ describe("SidebarIconRow", () => {
userMetadata: {
current: {
google: {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "HEALTHY",
},
},
Expand All @@ -130,7 +130,7 @@ describe("SidebarIconRow", () => {
userMetadata: {
current: {
google: {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "REPAIRING",
},
},
Expand All @@ -154,7 +154,7 @@ describe("SidebarIconRow", () => {
userMetadata: {
current: {
google: {
connectionStatus: "connected",
connectionStatus: "CONNECTED",
syncStatus: "ATTENTION",
},
},
Expand Down
Loading
Loading