Initial commit: Telegram Management System
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
35
marketing-agent/tests/helpers/database.js
Normal file
35
marketing-agent/tests/helpers/database.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { MongoMemoryServer } from 'mongodb-memory-server';
|
||||
|
||||
let mongoServer;
|
||||
|
||||
export const connectDatabase = async () => {
|
||||
mongoServer = await MongoMemoryServer.create();
|
||||
const uri = mongoServer.getUri();
|
||||
|
||||
await mongoose.connect(uri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const closeDatabase = async () => {
|
||||
await mongoose.connection.dropDatabase();
|
||||
await mongoose.connection.close();
|
||||
if (mongoServer) {
|
||||
await mongoServer.stop();
|
||||
}
|
||||
};
|
||||
|
||||
export const clearDatabase = async () => {
|
||||
const collections = mongoose.connection.collections;
|
||||
|
||||
for (const key in collections) {
|
||||
const collection = collections[key];
|
||||
await collection.deleteMany();
|
||||
}
|
||||
};
|
||||
|
||||
export const seedDatabase = async (model, data) => {
|
||||
return await model.create(data);
|
||||
};
|
||||
Reference in New Issue
Block a user