-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadmin.test.util.js
More file actions
47 lines (41 loc) · 1.02 KB
/
admin.test.util.js
File metadata and controls
47 lines (41 loc) · 1.02 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
const Util = {
Account: require("./account.test.util")
};
const Admin = require("../../models/admin.model");
const mongoose = require("mongoose");
const logger = require("../../services/logger.service");
const Admin0 = {
_id: mongoose.Types.ObjectId(),
accountId: Util.Account.adminAccounts.stored[0]
};
const Admins = [Admin0];
function store(attributes) {
const adminDocs = [];
const adminIds = [];
attributes.forEach((attribute) => {
adminDocs.push(new Admin(attribute));
adminIds.push(attribute._id);
});
return Admin.collection.insertMany(adminDocs);
}
async function storeAll() {
await store(Admins);
}
async function dropAll() {
try {
await Admin.collection.drop();
} catch (e) {
if (e.code === 26) {
logger.info("namespace %s not found", Admin.collection.name);
} else {
throw e;
}
}
}
module.exports = {
Admin0: Admin0,
Admins: Admins,
storeAll: storeAll,
dropAll: dropAll
};