forked from fr/deguapp
Added: tests, signin api, not working docker
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { Sequelize } from 'sequelize';
|
||||
|
||||
let sequelize: Sequelize | null = null;
|
||||
|
||||
const connectDB = async () => {
|
||||
sequelize = new Sequelize({
|
||||
dialect: 'mariadb',
|
||||
host: 'localhost',
|
||||
username: 'your_username',
|
||||
password: 'your_password',
|
||||
database: 'your_database',
|
||||
});
|
||||
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection to the database has been established successfully.');
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const dropDB = async () => {
|
||||
if (sequelize) {
|
||||
try {
|
||||
await sequelize.drop();
|
||||
console.log('Database dropped successfully.');
|
||||
} catch (error) {
|
||||
console.error('Error dropping database:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const dropTables = async () => {
|
||||
if (sequelize) {
|
||||
try {
|
||||
await sequelize.sync({ force: true });
|
||||
console.log('All tables dropped successfully.');
|
||||
} catch (error) {
|
||||
console.error('Error dropping tables:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { connectDB, dropDB, dropTables };
|
||||
30
api/src/utils/test_mongodb.ts
Normal file
30
api/src/utils/test_mongodb.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
|
||||
let mongo: any = null;
|
||||
|
||||
const connectDB = async () => {
|
||||
mongo = await MongoMemoryServer.create({ binary: { os: { os: 'linux', dist: 'ubuntu', release: '18.04' } } }); // TODO: check that host OS is Void Linux, else remove the argument
|
||||
const uri = mongo.getUri();
|
||||
|
||||
await mongoose.connect(uri);
|
||||
};
|
||||
|
||||
const dropDB = async () => {
|
||||
if (mongo) {
|
||||
await mongoose.connection.dropDatabase();
|
||||
await mongoose.connection.close();
|
||||
await mongo.stop();
|
||||
}
|
||||
};
|
||||
|
||||
const dropCollections = async () => {
|
||||
if (mongo) {
|
||||
const collections = await mongoose.connection.db.collections();
|
||||
for (let collection of collections) {
|
||||
await collection.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { connectDB, dropDB, dropCollections };
|
||||
Reference in New Issue
Block a user