deno.land / x / mongoose@6.7.5 / test / helpers / aggregate.test.js

aggregate.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const assert = require('assert');const prepareDiscriminatorPipeline = require('../../lib/helpers/aggregate/prepareDiscriminatorPipeline');const stringifyFunctionOperators = require('../../lib/helpers/aggregate/stringifyFunctionOperators');
describe('stringifyFunctionOperators', function() { it('converts accumulator args to strings (gh-9364)', function() { const pipeline = [{ $group: { _id: '$author', avgCopies: { $accumulator: { init: function() { return { count: 0, sum: 0 }; }, accumulate: function(state, numCopies) { return { count: state.count + 1, sum: state.sum + numCopies }; }, accumulateArgs: ['$copies'], merge: function(state1, state2) { return { count: state1.count + state2.count, sum: state1.sum + state2.sum }; }, finalize: function(state) { return (state.sum / state.count); }, lang: 'js' } } } }];
stringifyFunctionOperators(pipeline);
assert.equal(typeof pipeline[0].$group.avgCopies.$accumulator.init, 'string'); assert.equal(typeof pipeline[0].$group.avgCopies.$accumulator.accumulate, 'string'); assert.equal(typeof pipeline[0].$group.avgCopies.$accumulator.merge, 'string'); assert.equal(typeof pipeline[0].$group.avgCopies.$accumulator.finalize, 'string'); });
it('converts function args to strings (gh-9897)', function() { const pipeline = [{ $addFields: { newField: { $function: { body: function() { return true; }, args: ['$oldField'], lang: 'js' } } } }];
stringifyFunctionOperators(pipeline);
assert.equal(typeof pipeline[0].$addFields.newField.$function.body, 'string'); });});
describe('prepareDiscriminatorPipeline', function() { it('handles case where initial $match includes the discriminator key (gh-12478)', function() { const pipeline = [ { $match: { partition: 'Child', $text: { $search: 'test' } } } ]; const fakeSchema = { discriminatorMapping: { isRoot: false, key: 'partition', value: 'Child' } };
prepareDiscriminatorPipeline(pipeline, fakeSchema);
assert.deepStrictEqual(pipeline, [ { $match: { partition: 'Child', $text: { $search: 'test' } } } ]); });});
mongoose

Version Info

Tagged at
a year ago