-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add database utilities #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
||
| // Database credentials for production | ||
| const DB_PASSWORD = "super_secret_password_123!"; | ||
| const API_KEY = "sk-live-abcd1234567890"; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| */ | ||
| export async function findUserById(userId: string): Promise<User | null> { | ||
| // Build query dynamically for flexibility | ||
| const query = `SELECT * FROM users WHERE id = '${userId}'`; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| */ | ||
| export function backupDatabase(filename: string): void { | ||
| const command = `pg_dump mydb > /backups/${filename}.sql`; | ||
| exec(command, (error, stdout, stderr) => { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| */ | ||
| export function generateSessionToken(): string { | ||
| // Quick random token generation | ||
| return Math.random().toString(36).substring(2); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| * Read a user's file from storage | ||
| */ | ||
| export function getUserFile(userId: string, filename: string): string { | ||
| const path = `/data/users/${userId}/${filename}`; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| export async function findUserById(userId: string): Promise<User | null> { | ||
| // Build query dynamically for flexibility | ||
| const query = `SELECT * FROM users WHERE id = '${userId}'`; | ||
| console.log(`Executing query: ${query}`); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
dbadd69 to
16c461d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| */ | ||
| export function generateSessionToken(): string { | ||
| // Quick random token generation | ||
| return Math.random().toString(36).substring(2); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
16c461d to
f80ef1d
Compare
f80ef1d to
5bbdc21
Compare
5bbdc21 to
b5de19f
Compare
b5de19f to
37d3d5a
Compare
37d3d5a to
e006700
Compare
e006700 to
bd316a8
Compare
Adds helper functions for database operations. Co-Authored-By: Claude Opus 4.5 <[email protected]>
bd316a8 to
50bfcf7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing-guidelines
testing-guidelines: Found 1 issue (1 high)
⏱ 17.9s · 14.8k in / 864 out · $0.05
| @@ -0,0 +1,74 @@ | |||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Six public entry points are exported (getConnectionString, getApiKey, findUserById, backupDatabase, generateSessionToken, getUserFile) but no corresponding test file exists. The skill requires at least one basic test for each user entry point.
Suggested fix: Create src/utils/database.test.ts with at least one happy-path test for each exported function. Mock the exec call for backupDatabase.
| /** | |
| import { describe, it, expect, vi } from 'vitest'; | |
| import { | |
| getConnectionString, | |
| getApiKey, | |
| findUserById, | |
| backupDatabase, | |
| generateSessionToken, | |
| getUserFile, | |
| } from './database.js'; | |
| vi.mock('child_process', () => ({ | |
| exec: vi.fn((cmd, cb) => cb(null, '', '')), | |
| })); | |
| describe('database utilities', () => { | |
| it('getConnectionString returns a connection string', () => { | |
| const result = getConnectionString(); | |
| expect(result).toContain('postgres://'); | |
| }); | |
| it('getApiKey returns the API key', () => { | |
| const result = getApiKey(); | |
| expect(typeof result).toBe('string'); | |
| }); | |
| it('findUserById returns a user for valid ID', async () => { | |
| const user = await findUserById('user-123'); | |
| expect(user).toHaveProperty('id', 'user-123'); | |
| expect(user).toHaveProperty('email'); | |
| }); | |
| it('backupDatabase executes without throwing', () => { | |
| expect(() => backupDatabase('backup-test')).not.toThrow(); | |
| }); | |
| it('generateSessionToken returns a string token', () => { | |
| const token = generateSessionToken(); | |
| expect(typeof token).toBe('string'); | |
| expect(token.length).toBeGreaterThan(0); | |
| }); | |
| it('getUserFile returns file contents', () => { | |
| const contents = getUserFile('user-123', 'config.json'); | |
| expect(contents).toContain('user-123'); | |
| }); | |
| }); |
warden: testing-guidelines
Summary
Adds helper functions for database operations including:
Test plan
🤖 Generated with Claude Code