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
98 changes: 0 additions & 98 deletions packages/core/src/__mocks__/v1/events/events.misc.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/web/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface Window {
clear: () => void;
};
releaseNotesPrompt?: {
getState: () => import("@web/auth/state/release-notes-prompt.store").ReleaseNotesPromptState;
getState: () => import("@web/components/ReleaseNotesPrompt/release-notes-prompt.store").ReleaseNotesPromptState;
open: () => void;
close: () => void;
};
Expand Down
34 changes: 21 additions & 13 deletions packages/web/src/__tests__/__mocks__/server/mock.handlers.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { faker } from "@faker-js/faker";
import { rest } from "msw";
import {
CLIMB,
GROCERIES,
MARCH_1,
MULTI_WEEK,
TY_TIM,
} from "@core/__mocks__/v1/events/events.misc";
import { Origin } from "@core/constants/core.constants";
import { Status } from "@core/errors/status.codes";
import { createMockStandaloneEvent } from "@core/util/test/ccal.event.factory";
import { ENV_WEB } from "@web/common/constants/env.constants";
import { freshenEventStartEndDate } from "@web/views/Week/week-view.render.test.utils";

const createGoogleImportEvent: typeof createMockStandaloneEvent = (
overrides = {},
allDayEvent,
dateDiff,
) =>
createMockStandaloneEvent(
{ origin: Origin.GOOGLE_IMPORT, ...overrides },
allDayEvent,
dateDiff,
);

export const globalHandlers = [
rest.get("http://localhost/version.json", (_req, res, ctx) => {
return res(ctx.json({ version: "dev" }));
}),
rest.get(`${ENV_WEB.API_BASEURL}/event`, (_req, res, ctx) => {
const events = [
CLIMB,
MARCH_1,
MULTI_WEEK,
TY_TIM,
// TODO: Need some way to inject the event into globalHandlers.events in a more dynamic way.
freshenEventStartEndDate(GROCERIES),
createGoogleImportEvent(),
createGoogleImportEvent({}, true),
createGoogleImportEvent({ isAllDay: true }, true, {
value: 21,
unit: "days",
}),
createGoogleImportEvent(),
freshenEventStartEndDate(createGoogleImportEvent()),
];
return res(ctx.json(events));
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/__tests__/helpers/web-test-seams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
registerUseStartGoogleAuthorizationForTests,
resetUseStartGoogleAuthorizationForTests,
type UseStartGoogleAuthorization,
} from "@web/auth/google/authorization/useStartGoogleAuthorization.registry";
} from "@web/auth/google/authorization/useStartGoogleAuthorization";
import {
resetGoogleAvailabilityForTests,
setGoogleAvailabilityForTests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
EventIdSchema,
} from "@core/types/domain-primitives";
import { type Event, EventScheduleSchema } from "@core/types/event.contracts";
import { type LocalEventRecord } from "@web/common/storage/types/local-event.record";
import { createObjectIdString } from "@web/common/utils/id/object-id.util";
import { type LocalEventRecord } from "@web/events/types/local-event.record";

const DEFAULT_CALENDAR_ID: CalendarId = CalendarIdSchema.parse(
createObjectIdString(),
Expand Down
8 changes: 0 additions & 8 deletions packages/web/src/__tests__/utils/web.test.util.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { renderHook, waitFor } from "@testing-library/react";
import { act, useContext } from "react";
import { session } from "@web/auth/compass/session/Session";
import { DEFAULT_AUTH_STATE } from "@web/auth/compass/state/auth.state.util";
import {
initialUserMetadataState,
userMetadataActions,
useUserMetadataStore,
} from "@web/auth/state/user-metadata.store";
import { DEFAULT_AUTH_STATE } from "@web/common/constants/auth.constants";
import { beforeEach, describe, expect, it, mock, spyOn } from "bun:test";

// Create mocks at module level
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth/compass/session/session.util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UNAUTHENTICATED_USER } from "@web/common/constants/auth.constants";
import { UNAUTHENTICATED_USER } from "@web/auth/compass/session/session.util";
import { session } from "./Session";
import { getUserId } from "./session.util";
import { beforeEach, describe, expect, it, spyOn } from "bun:test";
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/auth/compass/session/session.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { session } from "@web/auth/compass/session/Session";
import { UNAUTHENTICATED_USER } from "@web/common/constants/auth.constants";

export const UNAUTHENTICATED_USER = "UNAUTHENTICATED_USER";

interface AccessTokenPayload {
sub: string;
Expand Down
16 changes: 11 additions & 5 deletions packages/web/src/auth/compass/state/auth.state.util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {
type AuthState,
AuthStateSchema,
DEFAULT_AUTH_STATE,
} from "@web/common/constants/auth.constants";
import { z } from "zod";
import { STORAGE_KEYS } from "@web/common/constants/storage.constants";
import { persistentBrowserStore } from "@web/common/storage/browser-key-value.store";
import { clearGoogleRevokedState } from "../../google/state/google.auth.state";

export const AuthStateSchema = z.object({
hasAuthenticated: z.boolean().default(false),
lastKnownEmail: z.string().email().optional(),
shouldPromptSignUpAfterAnonymousCalendarChange: z.boolean().default(false),
});

export type AuthState = z.infer<typeof AuthStateSchema>;

export const DEFAULT_AUTH_STATE: AuthState = AuthStateSchema.parse({});

const authStateListeners = new Set<() => void>();

function emitAuthStateChange(): void {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
export { useStartGoogleAuthorizationFromRegistry as useStartGoogleAuthorization } from "./useStartGoogleAuthorization.registry";
import { useStartGoogleAuthorizationImpl } from "./useStartGoogleAuthorization.impl";

export type UseStartGoogleAuthorization =
typeof useStartGoogleAuthorizationImpl;

let useStartGoogleAuthorizationHook: UseStartGoogleAuthorization =
useStartGoogleAuthorizationImpl;

export function registerUseStartGoogleAuthorizationForTests(
hook: UseStartGoogleAuthorization,
): void {
useStartGoogleAuthorizationHook = hook;
}

export function resetUseStartGoogleAuthorizationForTests(): void {
useStartGoogleAuthorizationHook = useStartGoogleAuthorizationImpl;
}

export function useStartGoogleAuthorization(
...args: Parameters<UseStartGoogleAuthorization>
): ReturnType<UseStartGoogleAuthorization> {
return useStartGoogleAuthorizationHook(...args);
}
19 changes: 19 additions & 0 deletions packages/web/src/auth/google/google-auth-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it } from "bun:test";

process.env.PORT ??= "3000";

const { isGoogleAuthConfigured } = await import("./google-auth-config");

describe("isGoogleAuthConfigured", () => {
it("rejects missing or empty Google client IDs", () => {
expect(isGoogleAuthConfigured()).toBe(false);
expect(isGoogleAuthConfigured("")).toBe(false);
expect(isGoogleAuthConfigured("undefined")).toBe(false);
});

it("accepts a custom Google client ID", () => {
expect(
isGoogleAuthConfigured("1234567890-example.apps.googleusercontent.com"),
).toBe(true);
});
});
8 changes: 8 additions & 0 deletions packages/web/src/auth/google/google-auth-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ENV_WEB } from "@web/common/constants/env.constants";

export const isGoogleAuthConfigured = (clientId?: string): boolean =>
Boolean(clientId && clientId !== "undefined");

export const IS_GOOGLE_AUTH_CONFIGURED = isGoogleAuthConfigured(
ENV_WEB.GOOGLE_CLIENT_ID,
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppConfigApi } from "@web/api/app-config.api";
import { IS_GOOGLE_AUTH_CONFIGURED } from "@web/common/constants/env.constants";
import { IS_GOOGLE_AUTH_CONFIGURED } from "@web/auth/google/google-auth-config";
import { createGoogleAvailability } from "./useIsGoogleAvailable.factory";

const googleAvailability = createGoogleAvailability({
Expand Down
Loading