From a092c57d3664c1883b0ba5ddfd69a548a24e6b70 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Wed, 17 Dec 2025 18:34:43 -0500 Subject: [PATCH] style test --- src/routes/test.tsx | 448 +++++++++++++++++++++++--------------------- 1 file changed, 237 insertions(+), 211 deletions(-) diff --git a/src/routes/test.tsx b/src/routes/test.tsx index 4665e82..f18668f 100644 --- a/src/routes/test.tsx +++ b/src/routes/test.tsx @@ -23,7 +23,8 @@ const routerSections: RouterSection[] = [ // ============================================================ { name: "Example Router", - description: "Example endpoints demonstrating public, protected, and admin procedures", + description: + "Example endpoints demonstrating public, protected, and admin procedures", endpoints: [ { name: "Hello", @@ -31,7 +32,7 @@ const routerSections: RouterSection[] = [ procedure: "hello", method: "query", description: "Simple hello world endpoint", - sampleInput: "World", + sampleInput: "World" }, { name: "Get Profile", @@ -39,7 +40,7 @@ const routerSections: RouterSection[] = [ procedure: "getProfile", method: "query", description: "Get authenticated user profile", - requiresAuth: true, + requiresAuth: true }, { name: "Admin Dashboard", @@ -47,9 +48,9 @@ const routerSections: RouterSection[] = [ procedure: "adminDashboard", method: "query", description: "Access admin dashboard", - requiresAdmin: true, - }, - ], + requiresAdmin: true + } + ] }, // ============================================================ @@ -68,8 +69,8 @@ const routerSections: RouterSection[] = [ sampleInput: { email: "newuser@example.com", password: "SecurePass123!", - passwordConfirmation: "SecurePass123!", - }, + passwordConfirmation: "SecurePass123!" + } }, { name: "Email Password Login", @@ -80,8 +81,8 @@ const routerSections: RouterSection[] = [ sampleInput: { email: "test@example.com", password: "SecurePass123!", - rememberMe: true, - }, + rememberMe: true + } }, { name: "Request Email Link Login", @@ -91,8 +92,8 @@ const routerSections: RouterSection[] = [ description: "Request magic link login email", sampleInput: { email: "test@example.com", - rememberMe: false, - }, + rememberMe: false + } }, { name: "Email Login (with token)", @@ -103,8 +104,8 @@ const routerSections: RouterSection[] = [ sampleInput: { email: "test@example.com", token: "eyJhbGciOiJIUzI1NiJ9...", - rememberMe: true, - }, + rememberMe: true + } }, { name: "Request Password Reset", @@ -113,8 +114,8 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Send password reset email", sampleInput: { - email: "test@example.com", - }, + email: "test@example.com" + } }, { name: "Reset Password", @@ -125,8 +126,8 @@ const routerSections: RouterSection[] = [ sampleInput: { token: "eyJhbGciOiJIUzI1NiJ9...", newPassword: "NewSecurePass123!", - newPasswordConfirmation: "NewSecurePass123!", - }, + newPasswordConfirmation: "NewSecurePass123!" + } }, { name: "Resend Email Verification", @@ -135,8 +136,8 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Resend verification email", sampleInput: { - email: "test@example.com", - }, + email: "test@example.com" + } }, { name: "Email Verification", @@ -146,15 +147,15 @@ const routerSections: RouterSection[] = [ description: "Verify email with token", sampleInput: { email: "test@example.com", - token: "eyJhbGciOiJIUzI1NiJ9...", - }, + token: "eyJhbGciOiJIUzI1NiJ9..." + } }, { name: "Sign Out", router: "auth", procedure: "signOut", method: "mutation", - description: "Clear session cookies and sign out", + description: "Clear session cookies and sign out" }, { name: "GitHub Callback", @@ -162,7 +163,7 @@ const routerSections: RouterSection[] = [ procedure: "githubCallback", method: "mutation", description: "Complete GitHub OAuth flow", - sampleInput: { code: "github_oauth_code_here" }, + sampleInput: { code: "github_oauth_code_here" } }, { name: "Google Callback", @@ -170,9 +171,9 @@ const routerSections: RouterSection[] = [ procedure: "googleCallback", method: "mutation", description: "Complete Google OAuth flow", - sampleInput: { code: "google_oauth_code_here" }, - }, - ], + sampleInput: { code: "google_oauth_code_here" } + } + ] }, // ============================================================ @@ -188,7 +189,7 @@ const routerSections: RouterSection[] = [ procedure: "getCommentReactions", method: "query", description: "Get all reactions for a comment", - sampleInput: { commentID: "comment_123" }, + sampleInput: { commentID: "comment_123" } }, { name: "Add Comment Reaction", @@ -199,8 +200,8 @@ const routerSections: RouterSection[] = [ sampleInput: { type: "👍", comment_id: "comment_123", - user_id: "user_123", - }, + user_id: "user_123" + } }, { name: "Remove Comment Reaction", @@ -211,10 +212,10 @@ const routerSections: RouterSection[] = [ sampleInput: { type: "👍", comment_id: "comment_123", - user_id: "user_123", - }, - }, - ], + user_id: "user_123" + } + } + ] }, { name: "Database - Comments", @@ -225,7 +226,7 @@ const routerSections: RouterSection[] = [ router: "database", procedure: "getAllComments", method: "query", - description: "Fetch all comments in the system", + description: "Fetch all comments in the system" }, { name: "Get Comments by Post ID", @@ -233,9 +234,9 @@ const routerSections: RouterSection[] = [ procedure: "getCommentsByPostId", method: "query", description: "Fetch comments for a specific post", - sampleInput: { post_id: "post_123" }, - }, - ], + sampleInput: { post_id: "post_123" } + } + ] }, { name: "Database - Posts", @@ -247,7 +248,7 @@ const routerSections: RouterSection[] = [ procedure: "getPostById", method: "query", description: "Fetch a post by ID with tags", - sampleInput: { category: "blog", id: 1 }, + sampleInput: { category: "blog", id: 1 } }, { name: "Get Post by Title", @@ -255,7 +256,7 @@ const routerSections: RouterSection[] = [ procedure: "getPostByTitle", method: "query", description: "Fetch post with comments, likes, and tags", - sampleInput: { category: "project", title: "My Project" }, + sampleInput: { category: "project", title: "My Project" } }, { name: "Create Post", @@ -271,8 +272,8 @@ const routerSections: RouterSection[] = [ banner_photo: null, published: false, tags: ["tech", "coding"], - author_id: "user_123", - }, + author_id: "user_123" + } }, { name: "Update Post", @@ -284,10 +285,10 @@ const routerSections: RouterSection[] = [ id: 1, title: "Updated Title", published: true, - author_id: "user_123", - }, - }, - ], + author_id: "user_123" + } + } + ] }, { name: "Database - Post Likes", @@ -299,7 +300,7 @@ const routerSections: RouterSection[] = [ procedure: "addPostLike", method: "mutation", description: "Add a like to a post", - sampleInput: { user_id: "user_123", post_id: "post_123" }, + sampleInput: { user_id: "user_123", post_id: "post_123" } }, { name: "Remove Post Like", @@ -307,9 +308,9 @@ const routerSections: RouterSection[] = [ procedure: "removePostLike", method: "mutation", description: "Remove a like from a post", - sampleInput: { user_id: "user_123", post_id: "post_123" }, - }, - ], + sampleInput: { user_id: "user_123", post_id: "post_123" } + } + ] }, { name: "Database - Users", @@ -321,7 +322,7 @@ const routerSections: RouterSection[] = [ procedure: "getUserById", method: "query", description: "Fetch complete user data by ID", - sampleInput: { id: "user_123" }, + sampleInput: { id: "user_123" } }, { name: "Get User Public Data", @@ -329,7 +330,7 @@ const routerSections: RouterSection[] = [ procedure: "getUserPublicData", method: "query", description: "Fetch public user data (email, name, image)", - sampleInput: { id: "user_123" }, + sampleInput: { id: "user_123" } }, { name: "Get User Image", @@ -337,7 +338,7 @@ const routerSections: RouterSection[] = [ procedure: "getUserImage", method: "query", description: "Fetch user image URL", - sampleInput: { id: "user_123" }, + sampleInput: { id: "user_123" } }, { name: "Update User Image", @@ -345,7 +346,7 @@ const routerSections: RouterSection[] = [ procedure: "updateUserImage", method: "mutation", description: "Update user profile image", - sampleInput: { id: "user_123", imageURL: "path/to/image.jpg" }, + sampleInput: { id: "user_123", imageURL: "path/to/image.jpg" } }, { name: "Update User Email", @@ -356,10 +357,10 @@ const routerSections: RouterSection[] = [ sampleInput: { id: "user_123", newEmail: "new@example.com", - oldEmail: "old@example.com", - }, - }, - ], + oldEmail: "old@example.com" + } + } + ] }, // ============================================================ @@ -375,7 +376,7 @@ const routerSections: RouterSection[] = [ procedure: "getProfile", method: "query", description: "Get current user's profile", - requiresAuth: true, + requiresAuth: true }, { name: "Update Email", @@ -384,7 +385,7 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Update user's email address", sampleInput: { email: "newemail@example.com" }, - requiresAuth: true, + requiresAuth: true }, { name: "Update Display Name", @@ -393,7 +394,7 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Update user's display name", sampleInput: { displayName: "New Display Name" }, - requiresAuth: true, + requiresAuth: true }, { name: "Update Profile Image", @@ -402,7 +403,7 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Update user's profile image URL", sampleInput: { imageUrl: "https://example.com/image.jpg" }, - requiresAuth: true, + requiresAuth: true }, { name: "Change Password", @@ -413,9 +414,9 @@ const routerSections: RouterSection[] = [ sampleInput: { oldPassword: "oldpass123", newPassword: "newpass123", - newPasswordConfirmation: "newpass123", + newPasswordConfirmation: "newpass123" }, - requiresAuth: true, + requiresAuth: true }, { name: "Set Password", @@ -425,9 +426,9 @@ const routerSections: RouterSection[] = [ description: "Set password for OAuth users", sampleInput: { newPassword: "newpass123", - newPasswordConfirmation: "newpass123", + newPasswordConfirmation: "newpass123" }, - requiresAuth: true, + requiresAuth: true }, { name: "Delete Account", @@ -436,9 +437,9 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Delete account (anonymize user data)", sampleInput: { password: "mypassword123" }, - requiresAuth: true, - }, - ], + requiresAuth: true + } + ] }, // ============================================================ @@ -454,9 +455,9 @@ const routerSections: RouterSection[] = [ procedure: "getDownloadUrl", method: "query", description: "Get signed S3 URL for asset download", - sampleInput: { asset_name: "shapes-with-abigail" }, - }, - ], + sampleInput: { asset_name: "shapes-with-abigail" } + } + ] }, { name: "Misc - S3 Operations", @@ -471,8 +472,8 @@ const routerSections: RouterSection[] = [ sampleInput: { type: "blog", title: "my-post", - filename: "image.jpg", - }, + filename: "image.jpg" + } }, { name: "Delete Image", @@ -484,8 +485,8 @@ const routerSections: RouterSection[] = [ key: "blog/my-post/image.jpg", newAttachmentString: "[]", type: "Post", - id: 1, - }, + id: 1 + } }, { name: "Simple Delete Image", @@ -493,9 +494,9 @@ const routerSections: RouterSection[] = [ procedure: "simpleDeleteImage", method: "mutation", description: "Delete image from S3 only", - sampleInput: { key: "blog/my-post/image.jpg" }, - }, - ], + sampleInput: { key: "blog/my-post/image.jpg" } + } + ] }, { name: "Misc - Password Utilities", @@ -507,7 +508,7 @@ const routerSections: RouterSection[] = [ procedure: "hashPassword", method: "mutation", description: "Hash a password with bcrypt", - sampleInput: { password: "mypassword123" }, + sampleInput: { password: "mypassword123" } }, { name: "Check Password", @@ -517,10 +518,10 @@ const routerSections: RouterSection[] = [ description: "Verify password against hash", sampleInput: { password: "mypassword123", - hash: "$2b$10$...", - }, - }, - ], + hash: "$2b$10$..." + } + } + ] }, // ============================================================ @@ -535,44 +536,44 @@ const routerSections: RouterSection[] = [ router: "lineage.jsonService", procedure: "items", method: "query", - description: "Get all item data (weapons, armor, potions, etc.)", + description: "Get all item data (weapons, armor, potions, etc.)" }, { name: "Get Attacks", router: "lineage.jsonService", procedure: "attacks", method: "query", - description: "Get all attack and spell data", + description: "Get all attack and spell data" }, { name: "Get Conditions", router: "lineage.jsonService", procedure: "conditions", method: "query", - description: "Get all condition and debilitation data", + description: "Get all condition and debilitation data" }, { name: "Get Dungeons", router: "lineage.jsonService", procedure: "dungeons", method: "query", - description: "Get all dungeon and encounter data", + description: "Get all dungeon and encounter data" }, { name: "Get Enemies", router: "lineage.jsonService", procedure: "enemies", method: "query", - description: "Get all enemy and boss data", + description: "Get all enemy and boss data" }, { name: "Get Misc", router: "lineage.jsonService", procedure: "misc", method: "query", - description: "Get misc game data (jobs, activities, etc.)", - }, - ], + description: "Get misc game data (jobs, activities, etc.)" + } + ] }, { name: "Lineage - Authentication", @@ -587,8 +588,8 @@ const routerSections: RouterSection[] = [ sampleInput: { email: "test@example.com", password: "password123", - password_conf: "password123", - }, + password_conf: "password123" + } }, { name: "Email Login", @@ -597,7 +598,7 @@ const routerSections: RouterSection[] = [ method: "mutation", description: "Login with email/password (requires verified email)", sampleInput: { email: "test@example.com", password: "password123" }, - requiresAuth: true, + requiresAuth: true }, { name: "Email Verification", @@ -605,7 +606,7 @@ const routerSections: RouterSection[] = [ procedure: "emailVerification", method: "mutation", description: "Verify email with token from email", - sampleInput: { token: "eyJhbGciOiJIUzI1NiJ9..." }, + sampleInput: { token: "eyJhbGciOiJIUzI1NiJ9..." } }, { name: "Refresh Verification Email", @@ -613,7 +614,7 @@ const routerSections: RouterSection[] = [ procedure: "refreshVerification", method: "mutation", description: "Resend verification email", - sampleInput: { email: "test@example.com" }, + sampleInput: { email: "test@example.com" } }, { name: "Refresh Auth Token", @@ -623,9 +624,9 @@ const routerSections: RouterSection[] = [ description: "Refresh expired JWT token", sampleInput: { email: "test@example.com", - authToken: "eyJhbGciOiJIUzI1NiJ9...", + authToken: "eyJhbGciOiJIUzI1NiJ9..." }, - requiresAuth: true, + requiresAuth: true }, { name: "Google Registration", @@ -633,7 +634,7 @@ const routerSections: RouterSection[] = [ procedure: "googleRegistration", method: "mutation", description: "Register/login with Google OAuth", - sampleInput: { idToken: "google_id_token_here" }, + sampleInput: { idToken: "google_id_token_here" } }, { name: "Apple Registration", @@ -643,8 +644,8 @@ const routerSections: RouterSection[] = [ description: "Register/login with Apple Sign In", sampleInput: { userString: "apple_user_string_here", - email: "user@privaterelay.appleid.com", - }, + email: "user@privaterelay.appleid.com" + } }, { name: "Apple Get Email", @@ -652,9 +653,9 @@ const routerSections: RouterSection[] = [ procedure: "appleGetEmail", method: "mutation", description: "Get email from Apple user string", - sampleInput: { userString: "apple_user_string_here" }, - }, - ], + sampleInput: { userString: "apple_user_string_here" } + } + ] }, { name: "Lineage - Database Management", @@ -669,9 +670,9 @@ const routerSections: RouterSection[] = [ sampleInput: { email: "test@example.com", provider: "email", - authToken: "jwt_token_here", + authToken: "jwt_token_here" }, - requiresAuth: true, + requiresAuth: true }, { name: "Init Deletion", @@ -683,9 +684,9 @@ const routerSections: RouterSection[] = [ email: "test@example.com", db_name: "db_name", db_token: "db_token", - authToken: "jwt_token", + authToken: "jwt_token" }, - requiresAuth: true, + requiresAuth: true }, { name: "Check Deletion Status", @@ -697,9 +698,9 @@ const routerSections: RouterSection[] = [ email: "test@example.com", db_name: "db_name", db_token: "db_token", - authToken: "jwt_token", + authToken: "jwt_token" }, - requiresAuth: true, + requiresAuth: true }, { name: "Cancel Deletion", @@ -711,18 +712,18 @@ const routerSections: RouterSection[] = [ email: "test@example.com", db_name: "db_name", db_token: "db_token", - authToken: "jwt_token", + authToken: "jwt_token" }, - requiresAuth: true, + requiresAuth: true }, { name: "Deletion Cron", router: "lineage.database", procedure: "deletionCron", method: "query", - description: "Cleanup expired databases (runs via cron)", - }, - ], + description: "Cleanup expired databases (runs via cron)" + } + ] }, { name: "Lineage - PvP", @@ -748,17 +749,17 @@ const routerSections: RouterSection[] = [ resistanceTable: "{}", damageTable: "{}", attackStrings: "[]", - knownSpells: "[]", + knownSpells: "[]" }, - linkID: "unique_player_id_here", - }, + linkID: "unique_player_id_here" + } }, { name: "Get Opponents", router: "lineage.pvp", procedure: "getOpponents", method: "query", - description: "Get 3 random PvP opponents", + description: "Get 3 random PvP opponents" }, { name: "Record Battle Result", @@ -768,10 +769,10 @@ const routerSections: RouterSection[] = [ description: "Record PvP battle outcome", sampleInput: { winnerID: "player_id_1", - loserID: "player_id_2", - }, - }, - ], + loserID: "player_id_2" + } + } + ] }, { name: "Lineage - Misc", @@ -791,8 +792,8 @@ const routerSections: RouterSection[] = [ proficiencies: { fire: 3 }, jobs: { blacksmith: 2 }, resistanceTable: { fire: 10 }, - damageTable: { physical: 5 }, - }, + damageTable: { physical: 5 } + } }, { name: "Update Device Token", @@ -800,16 +801,16 @@ const routerSections: RouterSection[] = [ procedure: "tokens", method: "mutation", description: "Register/update push notification token", - sampleInput: { token: "device_push_token_here" }, + sampleInput: { token: "device_push_token_here" } }, { name: "Offline Secret", router: "lineage.misc", procedure: "offlineSecret", method: "query", - description: "Get offline serialization secret", - }, - ], + description: "Get offline serialization secret" + } + ] }, { name: "Lineage - Maintenance (Admin Only)", @@ -821,7 +822,7 @@ const routerSections: RouterSection[] = [ procedure: "findLooseDatabases", method: "query", description: "Find orphaned databases not linked to users", - requiresAdmin: true, + requiresAdmin: true }, { name: "Cleanup Expired Databases", @@ -829,15 +830,15 @@ const routerSections: RouterSection[] = [ procedure: "cleanupExpiredDatabases", method: "query", description: "Delete databases past 24hr deletion window", - requiresAdmin: true, - }, - ], - }, + requiresAdmin: true + } + ] + } ]; export default function TestPage() { const [expandedSections, setExpandedSections] = createSignal>( - new Set(), + new Set() ); const [results, setResults] = createSignal>({}); const [loading, setLoading] = createSignal>({}); @@ -875,7 +876,7 @@ export default function TestPage() { let url = `/api/trpc/${endpoint.router}.${endpoint.procedure}`; const options: RequestInit = { method: endpoint.method === "query" ? "GET" : "POST", - headers: {}, + headers: {} }; // For queries, input goes in URL parameter @@ -883,7 +884,7 @@ export default function TestPage() { const encodedInput = encodeURIComponent(JSON.stringify(input)); url += `?input=${encodedInput}`; } - + // For mutations, input goes in body if (endpoint.method === "mutation" && input !== undefined) { options.headers = { "Content-Type": "application/json" }; @@ -910,16 +911,17 @@ export default function TestPage() { }; return ( -
-
-
-

tRPC API Testing Dashboard

-

- Complete API coverage: Example, Auth, Database, User, Misc, and Lineage routers +

+
+
+

tRPC API Testing Dashboard

+

+ Complete API coverage: Example, Auth, Database, User, Misc, and + Lineage routers

-
-

+

+

Quick Start: Expand any section below to test endpoints. Public endpoints work immediately. Auth-required endpoints need valid tokens. @@ -933,30 +935,28 @@ export default function TestPage() { const isExpanded = () => expandedSections().has(section.name); return ( -

+
{/* Section Header */} {/* Section Content */} -
+
{(endpoint) => { const key = `${endpoint.router}.${endpoint.procedure}`; @@ -966,44 +966,51 @@ export default function TestPage() { return inputEdits()[key]; } // Handle primitive values (string, number, boolean) - if (typeof endpoint.sampleInput === 'string') { + if (typeof endpoint.sampleInput === "string") { return `"${endpoint.sampleInput}"`; } - if (typeof endpoint.sampleInput === 'number' || typeof endpoint.sampleInput === 'boolean') { + if ( + typeof endpoint.sampleInput === "number" || + typeof endpoint.sampleInput === "boolean" + ) { return String(endpoint.sampleInput); } // Handle objects and arrays - return JSON.stringify(endpoint.sampleInput, null, 2); + return JSON.stringify( + endpoint.sampleInput, + null, + 2 + ); }; return ( -
+
{/* Endpoint Header */} -
+
-

+

{endpoint.name}

- + 🔒 Auth Required - + 👑 Admin Only
-

+

{endpoint.description}

-
- +
+ {key} - + {endpoint.method === "query" ? "GET" : "POST"} @@ -1013,7 +1020,7 @@ export default function TestPage() { @@ -1022,7 +1029,7 @@ export default function TestPage() { {/* Input Editor */}
-