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:
@@ -29,6 +29,7 @@ import {
|
||||
getSharedDb,
|
||||
initTestDb,
|
||||
TEST_RP,
|
||||
uniqueTestId,
|
||||
withTestTransaction,
|
||||
} from "@reviq/test-helpers";
|
||||
import { router } from "../../router.js";
|
||||
@@ -92,7 +93,7 @@ async function createSession(
|
||||
userId: number,
|
||||
options?: { ipAddress?: string; userAgent?: string },
|
||||
): 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);
|
||||
|
||||
@@ -125,9 +126,7 @@ async function createDevice(
|
||||
userAgent?: string;
|
||||
},
|
||||
): Promise<{ fingerprint: string; deviceId: number }> {
|
||||
const fingerprint =
|
||||
options?.fingerprint ??
|
||||
`test-fp-${String(Date.now())}${String(Math.random())}`;
|
||||
const fingerprint = options?.fingerprint ?? `test-fp-${uniqueTestId()}`;
|
||||
|
||||
const result = await db
|
||||
.insertInto("user_devices")
|
||||
@@ -153,7 +152,7 @@ async function createApiToken(
|
||||
db: Kysely<Database>,
|
||||
userId: number,
|
||||
): Promise<{ token: string; name: string }> {
|
||||
const token = `test-api-token-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `test-api-token-${uniqueTestId()}`;
|
||||
const tokenHashValue = await hashToken(token);
|
||||
const expiresAt = new Date(Date.now() + API_TOKEN_EXPIRY_MS);
|
||||
|
||||
@@ -224,7 +223,7 @@ describeE2E("me", () => {
|
||||
const user = await createTestUser(db, { email: "expired@example.com" });
|
||||
|
||||
// Create an expired session
|
||||
const token = `expired-session-${String(Date.now())}`;
|
||||
const token = `expired-session-${uniqueTestId()}`;
|
||||
const tokenHashValue = await hashToken(token);
|
||||
await db
|
||||
.insertInto("sessions")
|
||||
@@ -249,7 +248,7 @@ describeE2E("me", () => {
|
||||
const user = await createTestUser(db, { email: "revoked@example.com" });
|
||||
|
||||
// Create a revoked session
|
||||
const token = `revoked-session-${String(Date.now())}`;
|
||||
const token = `revoked-session-${uniqueTestId()}`;
|
||||
const tokenHashValue = await hashToken(token);
|
||||
await db
|
||||
.insertInto("sessions")
|
||||
@@ -925,7 +924,7 @@ describeE2E("me", () => {
|
||||
country: "US",
|
||||
trusted_mode: true,
|
||||
})
|
||||
.where("id", "=", String(sessionId))
|
||||
.where("id", "=", sessionId.toString())
|
||||
.execute();
|
||||
|
||||
const context = createAPIContext(db, { sessionToken });
|
||||
@@ -968,7 +967,7 @@ describeE2E("me", () => {
|
||||
const session = await db
|
||||
.selectFrom("sessions")
|
||||
.select(["revoked_at"])
|
||||
.where("id", "=", String(sessionId2))
|
||||
.where("id", "=", sessionId2.toString())
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
expect(session.revoked_at).not.toBeNull();
|
||||
@@ -1021,7 +1020,7 @@ describeE2E("me", () => {
|
||||
await db
|
||||
.updateTable("sessions")
|
||||
.set({ revoked_at: new Date() })
|
||||
.where("id", "=", String(sessionId2))
|
||||
.where("id", "=", sessionId2.toString())
|
||||
.execute();
|
||||
|
||||
const context = createAPIContext(db, { sessionToken: sessionToken1 });
|
||||
@@ -1080,7 +1079,7 @@ describeE2E("me", () => {
|
||||
const currentSession = await db
|
||||
.selectFrom("sessions")
|
||||
.select(["revoked_at"])
|
||||
.where("id", "=", String(id1))
|
||||
.where("id", "=", id1.toString())
|
||||
.executeTakeFirstOrThrow();
|
||||
expect(currentSession.revoked_at).toBeNull();
|
||||
|
||||
@@ -1088,7 +1087,7 @@ describeE2E("me", () => {
|
||||
const otherSessions = await db
|
||||
.selectFrom("sessions")
|
||||
.select(["id", "revoked_at"])
|
||||
.where("id", "in", [String(id2), String(id3)])
|
||||
.where("id", "in", [id2.toString(), id3.toString()])
|
||||
.execute();
|
||||
|
||||
for (const session of otherSessions) {
|
||||
@@ -1116,7 +1115,7 @@ describeE2E("me", () => {
|
||||
const session = await db
|
||||
.selectFrom("sessions")
|
||||
.select(["revoked_at"])
|
||||
.where("id", "=", String(sessionId))
|
||||
.where("id", "=", sessionId.toString())
|
||||
.executeTakeFirstOrThrow();
|
||||
expect(session.revoked_at).toBeNull();
|
||||
});
|
||||
@@ -1147,7 +1146,7 @@ describeE2E("me", () => {
|
||||
region: "NY",
|
||||
country: "US",
|
||||
})
|
||||
.where("id", "=", String(deviceId))
|
||||
.where("id", "=", deviceId.toString())
|
||||
.execute();
|
||||
|
||||
const { token: sessionToken } = await createSession(db, user.id);
|
||||
@@ -1256,7 +1255,7 @@ describeE2E("me", () => {
|
||||
const device = await db
|
||||
.selectFrom("user_devices")
|
||||
.select(["is_trusted", "name"])
|
||||
.where("id", "=", String(deviceId))
|
||||
.where("id", "=", deviceId.toString())
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
expect(device.is_trusted).toBe(true);
|
||||
@@ -1401,7 +1400,7 @@ describeE2E("me", () => {
|
||||
const device = await db
|
||||
.selectFrom("user_devices")
|
||||
.select(["is_trusted"])
|
||||
.where("id", "=", String(deviceId))
|
||||
.where("id", "=", deviceId.toString())
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
expect(device.is_trusted).toBe(false);
|
||||
@@ -1501,7 +1500,7 @@ async function createTrustedSession(
|
||||
db: Kysely<Database>,
|
||||
userId: number,
|
||||
): 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);
|
||||
|
||||
@@ -1568,7 +1567,7 @@ async function createOrgInvite(
|
||||
expiresAt?: Date;
|
||||
},
|
||||
): Promise<{ id: number }> {
|
||||
const token = `invite-token-${String(Date.now())}-${Math.random().toString(36).slice(2)}`;
|
||||
const token = `invite-token-${uniqueTestId()}-${Math.random().toString(36).slice(2)}`;
|
||||
const result = await db
|
||||
.insertInto("org_invites")
|
||||
.values({
|
||||
@@ -1693,7 +1692,7 @@ describeE2E("me.apiTokens and me.invites", () => {
|
||||
});
|
||||
|
||||
expect(tokens).toHaveLength(1);
|
||||
expect(tokens[0].name).toBe("User1 Token");
|
||||
expect(tokens[0]?.name).toBe("User1 Token");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1727,7 +1726,7 @@ describeE2E("me.apiTokens and me.invites", () => {
|
||||
.execute();
|
||||
|
||||
expect(tokens).toHaveLength(1);
|
||||
expect(tokens[0].name).toBe("My New Token");
|
||||
expect(tokens[0]?.name).toBe("My New Token");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1937,10 +1936,10 @@ describeE2E("me.apiTokens and me.invites", () => {
|
||||
});
|
||||
|
||||
expect(invites).toHaveLength(1);
|
||||
expect(invites[0].org.slug).toBe("invite-org");
|
||||
expect(invites[0].org.displayName).toBe("Invite Org");
|
||||
expect(invites[0].role).toBe("admin");
|
||||
expect(invites[0].invitedBy).toBe("Inviter Person");
|
||||
expect(invites[0]?.org.slug).toBe("invite-org");
|
||||
expect(invites[0]?.org.displayName).toBe("Invite Org");
|
||||
expect(invites[0]?.role).toBe("admin");
|
||||
expect(invites[0]?.invitedBy).toBe("Inviter Person");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2086,7 +2085,7 @@ describeE2E("me.apiTokens and me.invites", () => {
|
||||
describe("me.invites.accept", () => {
|
||||
test("accepts invite and adds user to org", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const inviter = await createTestUser(db, {
|
||||
email: `inviter-accept-${uniqueId}@example.com`,
|
||||
@@ -2188,7 +2187,7 @@ describeE2E("me.apiTokens and me.invites", () => {
|
||||
|
||||
test("returns error if already a member", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const inviter = await createTestUser(db, {
|
||||
email: `inviter-already-${uniqueId}@example.com`,
|
||||
|
||||
Reference in New Issue
Block a user