-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
41 lines (31 loc) · 942 Bytes
/
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
import test from 'ava';
import mongoose from 'mongoose';
import {MongoMemoryServer} from 'mongodb-memory-server';
import nm from './index.js';
test('Main', async t => {
const mongodb = await MongoMemoryServer.create();
mongoose.connect(mongodb.getUri(), {useNewUrlParser: true});
const personSchema = mongoose.Schema({
name: String,
age: Number,
email: String,
password: {type: String, private: true},
});
personSchema.plugin(nm);
const Person = mongoose.model('Person', personSchema);
t.true(personSchema.options.toJSON.transform instanceof Function, 'Check that toJSON.transform is a function');
const someone = new Person({
name: 'Abraham',
age: 7,
email: '[email protected]',
password: 'my_awesome_password',
});
someone.save();
const result = someone.toJSON();
const expected = {
age: 7,
email: '[email protected]',
name: 'Abraham',
};
t.deepEqual(result, {...expected, id: result.id});
});