- Domain: DeviceId, Command, DeviceParameter, DeviceProperty, Mode - Protocol: SOAP parsing, CWMPMessageBuilder (all methods) - References: config_loader, WassupProvider (timeout, errors) - Integration: MongoDB tests (CRUD, pagination, references) - Fix: Home.vue IP lookup for Device.WANDevice path - Total: 384 tests passing
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
/**
|
|
* Integration test setup — connects to local MongoDB and provides
|
|
* a clean database for each test suite.
|
|
*/
|
|
import { MongoClient, Db } from 'mongodb'
|
|
|
|
const MONGO_URI = 'mongodb://adam:adam@localhost:27017/adam-acs-test?authSource=admin'
|
|
const DB_NAME = 'adam-acs-test'
|
|
|
|
let client: MongoClient
|
|
let db: Db
|
|
|
|
export async function setupMongo(): Promise<Db> {
|
|
client = new MongoClient(MONGO_URI)
|
|
await client.connect()
|
|
db = client.db(DB_NAME)
|
|
|
|
// Monkey-patch getMongoDb to use our test DB
|
|
const provider = await import('../../providers/mongodb_provider.js')
|
|
;(provider as any).getMongoDb = () => db
|
|
// Also patch the module-level variable via a workaround
|
|
Object.defineProperty(await import('../../providers/mongodb_provider.js'), 'getMongoDb', {
|
|
value: () => db,
|
|
})
|
|
|
|
return db
|
|
}
|
|
|
|
export async function teardownMongo(): Promise<void> {
|
|
if (db) {
|
|
await db.dropDatabase()
|
|
}
|
|
if (client) {
|
|
await client.close()
|
|
}
|
|
}
|
|
|
|
export async function cleanCollections(): Promise<void> {
|
|
if (!db) return
|
|
const collections = await db.listCollections().toArray()
|
|
for (const col of collections) {
|
|
await db.collection(col.name).deleteMany({})
|
|
}
|
|
}
|
|
|
|
export function getTestDb(): Db {
|
|
return db
|
|
}
|