deno.land / x / mongoose@6.7.5 / test / model.translateAliases.test.js

model.translateAliases.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
/** * Test dependencies. */
'use strict';
const start = require('./common');
const assert = require('assert');
const mongoose = start.mongoose;
describe('model translate aliases', function() { it('should translate correctly', function() { const Syntax = new mongoose.Schema({ s: { type: String, alias: 'syntax' } });
const Character = mongoose.model('Character', new mongoose.Schema({ d: { type: Syntax, alias: 'dot' }, noAlias: { type: Syntax }, name: { type: String, alias: '名' }, bio: { age: { type: Number, alias: '年齢' } } }));
assert.deepEqual( // Translate aliases Character.translateAliases({ _id: '1',: 'Stark', 'noAlias.syntax': 'NoAliasSyntax', 年齢: 30, 'dot.syntax': 'DotSyntax', $and: [{ $or: [{: 'Stark' }, { 年齢: 30 }] }, { 'dot.syntax': 'DotSyntax' }] }), // How translated aliases suppose to look like { name: 'Stark', _id: '1', 'bio.age': 30, 'noAlias.s': 'NoAliasSyntax', 'd.s': 'DotSyntax', $and: [{ $or: [{ name: 'Stark' }, { 'bio.age': 30 }] }, { 'd.s': 'DotSyntax' }] } );
assert.deepEqual( // Translate aliases Character.translateAliases(new Map([ ['_id', '1'], ['名', 'Stark'], ['年齢', 30], ['dot.syntax', 'DotSyntax'], ['noAlias.syntax', 'NoAliasSyntax'] ])), // How translated aliases suppose to look like new Map([ ['name', 'Stark'], ['_id', '1'], ['bio.age', 30], ['d.s', 'DotSyntax'], ['noAlias.s', 'NoAliasSyntax'] ]) ); });});
mongoose

Version Info

Tagged at
a year ago