Skip to content
This repository was archived by the owner on Mar 20, 2020. It is now read-only.

Commit df8f5aa

Browse files
author
ao10
committed
Add stub back in
1 parent d91dee5 commit df8f5aa

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed
Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
'use strict';
22

33
const { MongoClient } = require('mongodb');
4+
const mock = require('mongodb-mock-server');
5+
// const server = mock.createServer();
46
const url = process.env.MONGODB_URI || 'mongodb://localhost:27017/';
57

8+
const { EventEmitter } = require('events');
9+
const { Db, Collection } = require('mongodb');
10+
11+
const origEval = Db.prototype.eval;
12+
Db.prototype.eval = async function overloadedEval(code, params, opts) {
13+
// run the original eval asynchronously, ignoring any errors it will throw since we aren't connected.
14+
try {
15+
origEval.call(this, code, params, opts);
16+
} catch (err) {
17+
// throw it away
18+
console.log(err);
19+
}
20+
return { code };
21+
};
22+
23+
const origRename = Collection.prototype.rename;
24+
Collection.prototype.rename = async function overloadedRename(name, options, callback) {
25+
try {
26+
origCreateCollection.call(this, name, options, callback);
27+
} catch (err) {
28+
console.log(err);
29+
}
30+
return { name };
31+
};
32+
33+
const topology = new EventEmitter();
34+
const db = new Db('testbench', topology, {});
35+
// Call Collection constructor
36+
const collection = new Collection(
37+
db,
38+
topology,
39+
'testbench',
40+
'collection',
41+
null,
42+
{}
43+
);
44+
645
/**
746
* @param {string} input user input string
847
* @param {Object} opts
@@ -15,13 +54,15 @@ module.exports['mongodb.Db.prototype.eval'] = async function _eval(
1554
) {
1655
if (noop) return 'NOOP';
1756

18-
const client = await MongoClient.connect(url);
57+
// const client = await MongoClient.connect(url);
58+
debugger;
1959

2060
const fn = safe ? 'function() {}' : input;
21-
const result = await client
22-
.db('testbench')
23-
.eval(fn)
24-
.catch(() => ({ code: fn }));
61+
const result = await db.eval(fn);
62+
// const result = await client
63+
// .db('testbench')
64+
// .eval(fn)
65+
// .catch(() => ({ code: fn }));
2566
return `<pre>${JSON.stringify(result, null, 2)}</pre>`;
2667
};
2768

@@ -35,14 +76,18 @@ module.exports['mongodb.Collection.prototype.rename'] = async function rename(
3576
input,
3677
{ safe = false, noop = false } = {}
3778
) {
38-
if (noop) return 'NOOP';
39-
40-
const client = await MongoClient.connect(url);
41-
const collection = await client.db('testbench').createCollection('new');
42-
79+
debugger;
4380
const newName = safe ? 'newName' : input;
44-
const result = await collection
45-
.rename(newName)
46-
.catch(() => ({ name: newName }));
81+
// const result = await collection.rename(newName);
82+
if (noop) return 'NOOP';
83+
const result = await collection.rename(newName);
4784
return `<pre>${JSON.stringify(result, null, 2)}</pre>`;
4885
};
86+
87+
// const client = await MongoClient.connect(url);
88+
// const collection = await client.db('testbench').createCollection('new');
89+
90+
// const newName = safe ? 'newName' : input;
91+
// const result = await collection
92+
// .rename(newName)
93+
// .catch(() => ({ name: newName }));

0 commit comments

Comments
 (0)