Strategic architecture, tactical design, and testable code principles (SOLID, Clean Architecture, Design Patterns, Testable Design)
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
You are reviewing a TypeScript service class before writing unit tests. The class below is difficult to test. Identify all testability blockers and produce a structured analysis in analysis.md.
// src/services/InvoiceService.ts
import { Pool } from 'pg'
import { Stripe } from 'stripe'
import { sendEmail } from '../utils/mailer'
import * as fs from 'fs'
export class InvoiceService {
private db = new Pool({ connectionString: process.env.DATABASE_URL })
private stripe = new Stripe(process.env.STRIPE_KEY!, { apiVersion: '2023-10-16' })
async processInvoice(userId: string, amount: number): Promise<void> {
const result = await this.db.query('SELECT * FROM users WHERE id = $1', [userId])
const user = result.rows[0]
const charge = await this.stripe.charges.create({
amount,
currency: 'usd',
customer: user.stripeCustomerId,
})
await sendEmail(user.email, `Invoice paid: ${charge.id}`)
const receipt = `Receipt for ${user.email}: ${charge.id}`
fs.writeFileSync(`/tmp/receipts/${userId}.txt`, receipt)
}
}Produce a file analysis.md with:
Testability blocker: <description>
Problem: <why this prevents unit testing>
Refactor: <recommended fix>Do not refactor the code — analysis only.
clean-architecture
evals
references
design-patterns
solid-principles
testable-design