Replace String() calls with .toString()/.toLocaleString() per ast-grep rule
- Add formatError() helper in CLI to safely handle unknown error types - Add uniqueTestId() helper for generating unique test identifiers - Replace String(id) with id.toString() for database ID conversions - Replace String(n) with n.toLocaleString() for user-facing number formatting - Fix TypeScript errors in test files (undefined checks, unused variables) - Update lint commands to include ast-grep scanning Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,7 @@ import {
|
||||
getSharedDb,
|
||||
initTestDb,
|
||||
TEST_RP,
|
||||
uniqueTestId,
|
||||
withTestTransaction,
|
||||
} from "@reviq/test-helpers";
|
||||
import { VirtualAuthenticator } from "@reviq/virtual-authenticator";
|
||||
@@ -146,7 +147,7 @@ async function createSession(
|
||||
userId: number,
|
||||
options?: { deviceId?: bigint },
|
||||
): Promise<{ token: string; sessionId: number }> {
|
||||
const token = `test-session-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `test-session-${uniqueTestId()}`;
|
||||
const tokenHashValue = await hashToken(token);
|
||||
const expiresAt = new Date(Date.now() + SESSION_EXPIRY_MS);
|
||||
|
||||
@@ -154,7 +155,7 @@ async function createSession(
|
||||
.insertInto("sessions")
|
||||
.values({
|
||||
user_id: userId,
|
||||
device_id: options?.deviceId ? String(options.deviceId) : null,
|
||||
device_id: options?.deviceId ? options.deviceId.toString() : null,
|
||||
token_hash: tokenHashValue,
|
||||
trusted_mode: false,
|
||||
expires_at: expiresAt,
|
||||
@@ -178,7 +179,7 @@ async function createLoginRequest(
|
||||
expiresAt?: Date;
|
||||
},
|
||||
): Promise<{ token: string; id: number }> {
|
||||
const token = `login_test-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `login_test-${uniqueTestId()}`;
|
||||
const expiresAt =
|
||||
options?.expiresAt ?? new Date(Date.now() + LOGIN_REQUEST_EXPIRY_MS);
|
||||
|
||||
@@ -228,7 +229,7 @@ async function createEmailVerification(
|
||||
userId: number,
|
||||
options?: { expiresAt?: Date },
|
||||
): Promise<string> {
|
||||
const token = `verify-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `verify-${uniqueTestId()}`;
|
||||
const expiresAt =
|
||||
options?.expiresAt ?? new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
|
||||
@@ -252,7 +253,7 @@ async function createPasswordReset(
|
||||
userId: number,
|
||||
options?: { expiresAt?: Date; usedAt?: Date | null },
|
||||
): Promise<string> {
|
||||
const token = `reset-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `reset-${uniqueTestId()}`;
|
||||
const expiresAt = options?.expiresAt ?? new Date(Date.now() + 60 * 60 * 1000);
|
||||
|
||||
await db
|
||||
@@ -457,7 +458,7 @@ describeE2E("auth", () => {
|
||||
const challenges = await db
|
||||
.selectFrom("webauthn_challenges")
|
||||
.selectAll()
|
||||
.where("id", "=", String(challengeId))
|
||||
.where("id", "=", challengeId.toString())
|
||||
.execute();
|
||||
expect(challenges.length).toBe(0);
|
||||
});
|
||||
@@ -483,7 +484,7 @@ describeE2E("auth", () => {
|
||||
await db
|
||||
.updateTable("webauthn_challenges")
|
||||
.set({ created_at: new Date(Date.now() - 20 * 60 * 1000) }) // 20 minutes ago
|
||||
.where("id", "=", String(challengeId))
|
||||
.where("id", "=", challengeId.toString())
|
||||
.execute();
|
||||
|
||||
// Step 4: Try to signup with expired challenge
|
||||
@@ -540,7 +541,7 @@ describeE2E("auth", () => {
|
||||
const challenges = await db
|
||||
.selectFrom("webauthn_challenges")
|
||||
.selectAll()
|
||||
.where("id", "=", String(challengeId))
|
||||
.where("id", "=", challengeId.toString())
|
||||
.execute();
|
||||
expect(challenges.length).toBe(0);
|
||||
});
|
||||
@@ -1072,7 +1073,7 @@ describeE2E("auth", () => {
|
||||
const loginRequest = await db
|
||||
.selectFrom("login_requests")
|
||||
.selectAll()
|
||||
.where("id", "=", String(loginRequestId))
|
||||
.where("id", "=", loginRequestId.toString())
|
||||
.executeTakeFirst();
|
||||
expect(loginRequest).toBeUndefined();
|
||||
|
||||
@@ -1152,7 +1153,7 @@ describeE2E("auth", () => {
|
||||
});
|
||||
|
||||
// Create login request without device fingerprint
|
||||
const token = `login_test-${String(Date.now())}`;
|
||||
const token = `login_test-${uniqueTestId()}`;
|
||||
await db
|
||||
.insertInto("login_requests")
|
||||
.values({
|
||||
@@ -1644,7 +1645,7 @@ describeE2E("auth", () => {
|
||||
const session = await db
|
||||
.selectFrom("sessions")
|
||||
.select(["revoked_at"])
|
||||
.where("id", "=", String(sessionId))
|
||||
.where("id", "=", sessionId.toString())
|
||||
.executeTakeFirst();
|
||||
|
||||
expect(session?.revoked_at).not.toBeNull();
|
||||
@@ -1981,7 +1982,7 @@ describeE2E("auth", () => {
|
||||
// Clean up registration session
|
||||
await db
|
||||
.deleteFrom("sessions")
|
||||
.where("id", "=", String(regSessionId))
|
||||
.where("id", "=", regSessionId.toString())
|
||||
.execute();
|
||||
|
||||
// Step 1: Create login request
|
||||
|
||||
Reference in New Issue
Block a user