forked from trent_larson/crowd-funder-for-time-pwa
fix: improve type safety and fix Playwright test dialog handling
**Type Safety Improvements:** - Replace `unknown[]` with proper `SqlValue[]` type in database query methods - Add `SqlValue` import to PlatformServiceMixin.ts for better type definitions - Update interface definitions for `$dbGetOneRow` and `$one` methods - Fix database row mapping to use `Array<SqlValue>` instead of `unknown[]` **Test Reliability Fix:** - Add backup seed modal handling to 60-new-activity.spec.ts - Follow established dialog handling pattern from 00-noid-tests.spec.ts - Use `waitForFunction` to detect backup seed modal appearance - Gracefully handle modal dismissal with "No, Remind me Later" button - Add error handling for cases where backup modal doesn't appear **Files Changed:** - src/utils/PlatformServiceMixin.ts: Enhanced type safety for database operations - test-playwright/60-new-activity.spec.ts: Fixed dialog interception causing test failures **Impact:** - Eliminates TypeScript linting errors for database query types - Resolves Playwright test timeout caused by backup seed modal blocking clicks - Improves test reliability by following established dialog handling patterns - Maintains backward compatibility while enhancing type safety **Testing:** - TypeScript compilation passes without errors - Linting checks pass with improved type definitions - Playwright test now handles backup seed modal properly
This commit is contained in:
@@ -52,7 +52,11 @@ import { logger } from "@/utils/logger";
|
||||
import { Contact, ContactMaybeWithJsonStrings } from "@/db/tables/contacts";
|
||||
import { Account } from "@/db/tables/accounts";
|
||||
import { Temp } from "@/db/tables/temp";
|
||||
import { QueryExecResult, DatabaseExecResult } from "@/interfaces/database";
|
||||
import {
|
||||
QueryExecResult,
|
||||
DatabaseExecResult,
|
||||
SqlValue,
|
||||
} from "@/interfaces/database";
|
||||
import {
|
||||
generateInsertStatement,
|
||||
generateUpdateStatement,
|
||||
@@ -285,7 +289,7 @@ export const PlatformServiceMixin = {
|
||||
return [];
|
||||
}
|
||||
|
||||
return result.values.map((row: unknown[]) => row[0] as string);
|
||||
return result.values.map((row: SqlValue[]) => row[0] as string);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
"[PlatformServiceMixin] Error getting available account DIDs:",
|
||||
@@ -498,7 +502,10 @@ export const PlatformServiceMixin = {
|
||||
/**
|
||||
* Enhanced database single row query method with error handling
|
||||
*/
|
||||
async $dbGetOneRow(sql: string, params?: unknown[]) {
|
||||
async $dbGetOneRow(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<SqlValue[] | undefined> {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return await (this as any).platformService.dbGetOneRow(sql, params);
|
||||
@@ -699,7 +706,7 @@ export const PlatformServiceMixin = {
|
||||
|
||||
if (availableAccounts?.values?.length) {
|
||||
const accountDids = availableAccounts.values.map(
|
||||
(row: unknown[]) => row[0] as string,
|
||||
(row: SqlValue[]) => row[0] as string,
|
||||
);
|
||||
logger.debug(
|
||||
"[PlatformServiceMixin] Available accounts for user selection:",
|
||||
@@ -749,7 +756,9 @@ export const PlatformServiceMixin = {
|
||||
const result = await this.$dbQuery(
|
||||
"SELECT did FROM accounts ORDER BY dateCreated, did",
|
||||
);
|
||||
return result?.values?.map((row: unknown[]) => row[0] as string) || [];
|
||||
return (
|
||||
result?.values?.map((row: Array<SqlValue>) => row[0] as string) || []
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -856,7 +865,7 @@ export const PlatformServiceMixin = {
|
||||
async $one(
|
||||
sql: string,
|
||||
params: unknown[] = [],
|
||||
): Promise<unknown[] | undefined> {
|
||||
): Promise<SqlValue[] | undefined> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return await (this as any).platformService.dbGetOneRow(sql, params);
|
||||
},
|
||||
@@ -1900,7 +1909,10 @@ export interface IPlatformServiceMixin {
|
||||
params?: unknown[],
|
||||
): Promise<QueryExecResult | undefined>;
|
||||
$dbExec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>;
|
||||
$dbGetOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
|
||||
$dbGetOneRow(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<SqlValue[] | undefined>;
|
||||
$getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
|
||||
$getMergedSettings(
|
||||
defaultKey: string,
|
||||
@@ -2004,7 +2016,7 @@ declare module "@vue/runtime-core" {
|
||||
// Ultra-concise database methods (shortest possible names)
|
||||
$db(sql: string, params?: unknown[]): Promise<QueryExecResult | undefined>;
|
||||
$exec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>;
|
||||
$one(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
|
||||
$one(sql: string, params?: unknown[]): Promise<SqlValue[] | undefined>;
|
||||
|
||||
// Query + mapping combo methods
|
||||
$query<T = Record<string, unknown>>(
|
||||
|
||||
Reference in New Issue
Block a user