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:
@@ -36,6 +36,7 @@ import {
|
||||
initTestDb,
|
||||
TEST_RP,
|
||||
truncateAllTables,
|
||||
uniqueTestId,
|
||||
withTestTransaction,
|
||||
} from "@reviq/test-helpers";
|
||||
import { router } from "../../router.js";
|
||||
@@ -84,7 +85,7 @@ async function createSession(
|
||||
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);
|
||||
|
||||
@@ -115,9 +116,7 @@ async function createOrg(
|
||||
logoUrl?: string;
|
||||
},
|
||||
): Promise<{ id: number; slug: string }> {
|
||||
const slug =
|
||||
options?.slug ??
|
||||
`org-${String(Date.now())}-${String(Math.random()).slice(2, 8)}`;
|
||||
const slug = options?.slug ?? `org-${uniqueTestId()}`;
|
||||
|
||||
const result = await db
|
||||
.insertInto("orgs")
|
||||
@@ -183,7 +182,7 @@ async function createLoginRequest(
|
||||
expiresAt?: Date;
|
||||
},
|
||||
): Promise<{ id: number; token: string }> {
|
||||
const token = `login-${String(Date.now())}${String(Math.random())}`;
|
||||
const token = `login-${uniqueTestId()}`;
|
||||
const expiresAt =
|
||||
options?.expiresAt ?? new Date(Date.now() + LOGIN_REQUEST_EXPIRY_MS);
|
||||
|
||||
@@ -212,7 +211,7 @@ async function createOrgInvite(
|
||||
email: string,
|
||||
invitedBy: number,
|
||||
): Promise<{ id: number }> {
|
||||
const token = `invite-${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const token = `invite-${uniqueTestId()}`;
|
||||
const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000); // 7 days
|
||||
|
||||
const result = await db
|
||||
@@ -461,7 +460,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("creates passwordless user", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -492,7 +491,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("creates user with name", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -519,7 +518,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("creates user and adds to organization as member", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -554,7 +553,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("creates user and adds to organization with custom role", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -588,7 +587,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("normalizes email to lowercase", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -615,7 +614,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws CONFLICT for duplicate email", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -637,7 +636,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws NOT_FOUND for non-existent org", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1060,7 +1059,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("creates organization with owner", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1109,7 +1108,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("normalizes owner email to lowercase", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1135,7 +1134,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws NOT_FOUND for non-existent owner", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1160,7 +1159,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws CONFLICT for duplicate slug", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1284,7 +1283,7 @@ describeE2E("admin", () => {
|
||||
await createOrg(db, {
|
||||
slug: "test-org",
|
||||
displayName: "Old",
|
||||
logoUrl: null,
|
||||
logoUrl: undefined,
|
||||
});
|
||||
|
||||
const { token: sessionToken } = await createSession(db, admin.id);
|
||||
@@ -1379,7 +1378,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("deletes organization and related records", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1444,7 +1443,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws NOT_FOUND for non-existent organization", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1564,7 +1563,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("adds site to organization", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1596,7 +1595,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws NOT_FOUND for non-existent organization", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1617,7 +1616,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws CONFLICT for duplicate domain", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1640,7 +1639,7 @@ describeE2E("admin", () => {
|
||||
|
||||
test("throws CONFLICT for domain in another organization", async () => {
|
||||
const db = getSharedDb();
|
||||
const uniqueId = `${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const uniqueId = uniqueTestId();
|
||||
|
||||
const admin = await createTestUser(db, {
|
||||
email: `admin-${uniqueId}@example.com`,
|
||||
@@ -1793,7 +1792,7 @@ describeE2E("admin", () => {
|
||||
// Verify login request was completed
|
||||
const request = await db
|
||||
.selectFrom("login_requests")
|
||||
.where("id", "=", String(loginRequest.id))
|
||||
.where("id", "=", loginRequest.id.toString())
|
||||
.select(["completed_at"])
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
@@ -1825,7 +1824,7 @@ describeE2E("admin", () => {
|
||||
|
||||
const request = await db
|
||||
.selectFrom("login_requests")
|
||||
.where("id", "=", String(loginRequest.id))
|
||||
.where("id", "=", loginRequest.id.toString())
|
||||
.select(["completed_at"])
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user