PROBLEM: 10/26 integration test suites hanging (API tests) - Tests import app but don't connect required databases - Tractatus uses TWO separate DB connections (native + Mongoose) - Tests only connected one, causing hangs when routes accessed User model INVESTIGATION: - Created minimal.test.js - diagnostic test (passes) - Identified root cause: dual database architecture - Updated api.auth.test.js with both connections (still investigating hang) CREATED: - tests/helpers/db-test-helper.js - Unified database setup helper Exports setupDatabases() and cleanupDatabases() Connects both native MongoDB driver AND Mongoose Ready for use in all integration tests PARTIAL FIX: - tests/integration/api.auth.test.js - Updated to connect both DBs - Still investigating why tests hang (likely response field mismatch) NEXT SESSION: 1. Apply db-test-helper to all 7 API integration tests 2. Fix response field mismatches (accessToken vs token) 3. Verify all tests pass IMPACT: Test helper provides pattern for fixing all integration tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
924 B
JavaScript
39 lines
924 B
JavaScript
/**
|
|
* Database Test Helper
|
|
* Provides unified database setup for integration tests
|
|
*
|
|
* USAGE:
|
|
* const { setupDatabases, cleanupDatabases } = require('../helpers/db-test-helper');
|
|
*
|
|
* beforeAll(async () => {
|
|
* await setupDatabases();
|
|
* });
|
|
*
|
|
* afterAll(async () => {
|
|
* await cleanupDatabases();
|
|
* });
|
|
*/
|
|
|
|
const mongoose = require('mongoose');
|
|
const { connect: connectDb, close: closeDb } = require('../../src/utils/db.util');
|
|
const config = require('../../src/config/app.config');
|
|
|
|
async function setupDatabases() {
|
|
// Connect native MongoDB driver (for User model and native queries)
|
|
await connectDb();
|
|
|
|
// Connect Mongoose (for Mongoose models)
|
|
if (mongoose.connection.readyState === 0) {
|
|
await mongoose.connect(config.mongodb.uri);
|
|
}
|
|
}
|
|
|
|
async function cleanupDatabases() {
|
|
await mongoose.disconnect();
|
|
await closeDb();
|
|
}
|
|
|
|
module.exports = {
|
|
setupDatabases,
|
|
cleanupDatabases
|
|
};
|