This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (54 loc) · 1.87 KB
/
test.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var Mongify = require('./');
var Mongodb = require('mongodb');
var Lab = require('lab');
var Chai = require('chai');
Chai.should();
var it = Lab.test;
Lab.experiment('mongify', function(){
it('should convert an ObjectID string (24hex string) to a Mongodb.ObjectID', function(done){
Mongify('523396be6a51026f63000001').should.eql(new Mongodb.ObjectID('523396be6a51026f63000001'));
done();
}),
it('should keep the string "a message" unchanged', function(done){
Mongify('a message').should.eql("a message");
done();
}),
it('should keep a Mongo.ObjectID unchanged', function(done){
Mongify(new Mongodb.ObjectID('523396be6a51026f63000001')).should.eql(new Mongodb.ObjectID('523396be6a51026f63000001'));
done();
}),
it('should convert an object with a 24-hex string to an ObjectID', function(done){
var anObject = {
content: { },
_id: '523396be6a51026f63000001'
}
Mongify(anObject).should.eql({
content: { },
_id: new Mongodb.ObjectID('523396be6a51026f63000001')
});
done();
}),
it('should return a different object then the one it was converting', function(done){
var anObject = {
content: { },
_id: '523396be6a51026f63000009'
}
Mongify(anObject).should.not.equal(anObject);
done();
}),
it('should convert an object with nested 24-hex strings to an object with ObjectIDs', function(done){
var anObject = {
number: 3441,
_id: new Mongodb.ObjectID(),
content: { content_id: '523396be6a51026f63000009', i: {am: {losing: {it_id: '523396be6a51026f63000009', yep: "i am"}}}},
super_id: '523396be6a51026f63000009'
}
Mongify(anObject).should.eql({
number: 3441,
_id: anObject._id,
content: { content_id: new Mongodb.ObjectID('523396be6a51026f63000009'), i: {am: {losing: {it_id: new Mongodb.ObjectID('523396be6a51026f63000009'), yep: "i am"}}}},
super_id: new Mongodb.ObjectID('523396be6a51026f63000009')
});
done();
});
});