forked from random-guys/backend-developer-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testDB.js
33 lines (28 loc) · 812 Bytes
/
testDB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import mongoose from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
class TestDbHelper {
constructor() {
this.db = null;
this.server = new MongoMemoryServer({
useUnifiedTopology: true,
});
this.connection = null;
}
/**
* Start the server and establish a connection
*/
async start() {
const mongoUri = await this.server.getConnectionString();
this.connection = await mongoose.connect(mongoUri, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
}
async stop() {
await this.connection.disconnect();
return this.server.stop();
}
}
export default TestDbHelper;