57
scripts/smoke-integration.ts
Normal file
57
scripts/smoke-integration.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Local integration smoke checks: Postgres via Prisma adapter + optional Stripe API ping.
|
||||
* Does not hit Next.js HTTP routes (use npm run test:http after starting the server).
|
||||
*/
|
||||
import "dotenv/config";
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { Pool } from "pg";
|
||||
import Stripe from "stripe";
|
||||
|
||||
async function main() {
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
if (!connectionString) {
|
||||
throw new Error("DATABASE_URL is not set");
|
||||
}
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const prisma = new PrismaClient({ adapter: new PrismaPg(pool) });
|
||||
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
|
||||
const counts = await prisma.$transaction([
|
||||
prisma.user.count(),
|
||||
prisma.wallet.count(),
|
||||
prisma.donation.count(),
|
||||
prisma.ledgerEntry.count(),
|
||||
]);
|
||||
|
||||
console.log("[db] connected OK");
|
||||
console.log("[db] counts — users:", counts[0], "wallets:", counts[1], "donations:", counts[2], "ledger:", counts[3]);
|
||||
|
||||
const admins = await prisma.user.count({ where: { role: "ADMIN" } });
|
||||
console.log("[db] admin users:", admins);
|
||||
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
|
||||
const sk = process.env.STRIPE_SECRET_KEY?.trim();
|
||||
if (!sk || sk.includes("disabled_configure")) {
|
||||
console.log("[stripe] skipped — set STRIPE_SECRET_KEY to call the Stripe API");
|
||||
return;
|
||||
}
|
||||
|
||||
const stripe = new Stripe(sk, { typescript: true });
|
||||
try {
|
||||
const balance = await stripe.balance.retrieve();
|
||||
const cur = new Set([...balance.available, ...balance.pending].map((b) => b.currency));
|
||||
console.log("[stripe] balance.retrieve OK — currencies:", [...cur].join(", ") || "(none)");
|
||||
} catch (e) {
|
||||
console.log("[stripe] balance.retrieve failed — check key mode (test/live) and permissions:", (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error("[smoke] failed:", e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user