deno.land / x / mongoose@6.7.5 / test / plugin.idGetter.test.js

plugin.idGetter.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
65
66
67
68
69
70
71
'use strict';
/** * Module dependencies. */
const start = require('./common');
const assert = require('assert');
const mongoose = start.mongoose;const Schema = mongoose.Schema;
describe('id virtual getter', function() { let db;
before(function() { db = start(); });
after(async function() { await db.close(); });
beforeEach(() => db.deleteModel(/.*/)); afterEach(() => require('./util').clearTestData(db)); afterEach(() => require('./util').stopRemainingOps(db));
it('should work as expected with an ObjectId', function(done) { const schema = new Schema({});
const S = db.model('Test', schema); S.create({}, function(err, s) { assert.ifError(err);
// Comparing with virtual getter assert.equal(s._id.toString(), s.id); done(); }); });
it('should be turned off when `id` option is set to false', function(done) { const schema = new Schema({}, { id: false });
const S = db.model('Test', schema); S.create({}, function(err, s) { assert.ifError(err);
// Comparing with virtual getter assert.equal(s.id, undefined); done(); }); });

it('should be turned off when the schema has a set `id` path', function(done) { const schema = new Schema({ id: String });
const S = db.model('Test', schema); S.create({ id: 'test' }, function(err, s) { assert.ifError(err);
// Comparing with expected value assert.equal(s.id, 'test'); done(); }); });});
mongoose

Version Info

Tagged at
a year ago