-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
47 lines (39 loc) · 949 Bytes
/
Copy pathtest.js
File metadata and controls
47 lines (39 loc) · 949 Bytes
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 MongoClient = require("mongodb").MongoClient;
const test = require("tape");
const MONGO_PORT = 27777;
let db, docs;
test("connecting to mongod", t => {
MongoClient.connect(`mongodb://localhost:${MONGO_PORT}/hello`).then(_db => {
t.pass("MongoDB connection");
db = _db;
}).then(t.end, t.end);
});
test("prepare", t => {
docs = db.collection("documents");
docs.remove({}).then(res => {
t.ok(res.result.ok);
}).then(t.end, t.end);
});
test("create", t => {
docs.insertMany([
{_id: 1, a: 111},
{_id: 2, a: 222},
{_id: 3, a: 333}
]).then(res => {
t.equal(res.insertedCount, 3);
}).then(t.end, t.end);
});
test("read", t => {
docs.find({_id: {$in: [1, 2, 3]}}).toArray().then(res => {
t.deepEqual(res, [
{_id: 1, a: 111},
{_id: 2, a: 222},
{_id: 3, a: 333}
]);
}).then(t.end, t.end);
});
test("shutting down mongod", t => {
db.close();
t.end();
});