Fix stale app UI (supabase) & overall E2E test infra improvements (#337)
Fixes #269
This commit is contained in:
@@ -3,6 +3,7 @@ import log from "electron-log";
|
||||
import { createLoggedHandler } from "./safe_handle";
|
||||
import { readSettings } from "../../main/settings"; // Assuming settings are read this way
|
||||
import { UserBudgetInfo, UserBudgetInfoSchema } from "../ipc_types";
|
||||
import { IS_TEST_BUILD } from "../utils/test_utils";
|
||||
|
||||
const logger = log.scope("pro_handlers");
|
||||
const handle = createLoggedHandler(logger);
|
||||
@@ -13,6 +14,10 @@ export function registerProHandlers() {
|
||||
// This method should try to avoid throwing errors because this is auxiliary
|
||||
// information and isn't critical to using the app
|
||||
handle("get-user-budget", async (): Promise<UserBudgetInfo | null> => {
|
||||
if (IS_TEST_BUILD) {
|
||||
// Avoid spamming the API in E2E tests.
|
||||
return null;
|
||||
}
|
||||
logger.info("Attempting to fetch user budget information.");
|
||||
|
||||
const settings = readSettings();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ipcMain, IpcMainInvokeEvent } from "electron";
|
||||
import log from "electron-log";
|
||||
import { IS_TEST_BUILD } from "../utils/test_utils";
|
||||
|
||||
export function createLoggedHandler(logger: log.LogFunctions) {
|
||||
return (
|
||||
@@ -27,3 +28,11 @@ export function createLoggedHandler(logger: log.LogFunctions) {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestOnlyLoggedHandler(logger: log.LogFunctions) {
|
||||
if (!IS_TEST_BUILD) {
|
||||
// Returns a no-op function for non-e2e test builds.
|
||||
return () => {};
|
||||
}
|
||||
return createLoggedHandler(logger);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,15 @@ import { db } from "../../db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { apps } from "../../db/schema";
|
||||
import { getSupabaseClient } from "../../supabase_admin/supabase_management_client";
|
||||
import { createLoggedHandler } from "./safe_handle";
|
||||
import {
|
||||
createLoggedHandler,
|
||||
createTestOnlyLoggedHandler,
|
||||
} from "./safe_handle";
|
||||
import { handleSupabaseOAuthReturn } from "../../supabase_admin/supabase_return_handler";
|
||||
|
||||
const logger = log.scope("supabase_handlers");
|
||||
const handle = createLoggedHandler(logger);
|
||||
const testOnlyHandle = createTestOnlyLoggedHandler(logger);
|
||||
|
||||
export function registerSupabaseHandlers() {
|
||||
handle("supabase:list-projects", async () => {
|
||||
@@ -36,4 +41,42 @@ export function registerSupabaseHandlers() {
|
||||
|
||||
logger.info(`Removed Supabase project association for app ${app}`);
|
||||
});
|
||||
|
||||
testOnlyHandle(
|
||||
"supabase:fake-connect-and-set-project",
|
||||
async (
|
||||
event,
|
||||
{ appId, fakeProjectId }: { appId: number; fakeProjectId: string },
|
||||
) => {
|
||||
// Call handleSupabaseOAuthReturn with fake data
|
||||
handleSupabaseOAuthReturn({
|
||||
token: "fake-access-token",
|
||||
refreshToken: "fake-refresh-token",
|
||||
expiresIn: 3600, // 1 hour
|
||||
});
|
||||
logger.info(
|
||||
`Called handleSupabaseOAuthReturn with fake data for app ${appId} during testing.`,
|
||||
);
|
||||
|
||||
// Set the supabase project for the currently selected app
|
||||
await db
|
||||
.update(apps)
|
||||
.set({
|
||||
supabaseProjectId: fakeProjectId,
|
||||
})
|
||||
.where(eq(apps.id, appId));
|
||||
logger.info(
|
||||
`Set fake Supabase project ${fakeProjectId} for app ${appId} during testing.`,
|
||||
);
|
||||
|
||||
// Simulate the deep link event
|
||||
event.sender.send("deep-link-received", {
|
||||
type: "supabase-oauth-return",
|
||||
url: "https://supabase-oauth.dyad.sh/api/connect-supabase/login",
|
||||
});
|
||||
logger.info(
|
||||
`Sent fake deep-link-received event for app ${appId} during testing.`,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user