forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.type.test.js
33 lines (27 loc) · 1.12 KB
/
schema.type.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
'use strict';
/**
* Module dependencies.
*/
const mongoose = require('./common').mongoose;
const assert = require('assert');
const Schema = mongoose.Schema;
describe('schematype', function() {
it('honors the selected option', function(done) {
const s = new Schema({thought: {type: String, select: false}});
assert.ok(!s.path('thought').selected);
const a = new Schema({thought: {type: String, select: true}});
assert.ok(a.path('thought').selected);
done();
});
it('properly handles specifying index in combination with unique or sparse', function(done) {
let s = new Schema({name: {type: String, index: true, unique: true}});
assert.deepEqual(s.path('name')._index, {unique: true});
s = new Schema({name: {type: String, unique: true, index: true}});
assert.deepEqual(s.path('name')._index, {unique: true});
s = new Schema({name: {type: String, index: true, sparse: true}});
assert.deepEqual(s.path('name')._index, {sparse: true});
s = new Schema({name: {type: String, sparse: true, index: true}});
assert.deepEqual(s.path('name')._index, {sparse: true});
done();
});
});