@@ -4,10 +4,23 @@ const Config = require('../lib/Config');
4
4
const TestUtils = require ( '../lib/TestUtils' ) ;
5
5
const { MongoClient } = require ( 'mongodb' ) ;
6
6
const databaseURI = 'mongodb://localhost:27017/' ;
7
+ const request = require ( '../lib/request' ) ;
7
8
8
9
let config , client , database ;
9
10
10
- describe_only_db ( 'mongo' ) ( 'Parse.Query testing' , ( ) => {
11
+ const masterKeyHeaders = {
12
+ 'X-Parse-Application-Id' : 'test' ,
13
+ 'X-Parse-Rest-API-Key' : 'rest' ,
14
+ 'X-Parse-Master-Key' : 'test' ,
15
+ 'Content-Type' : 'application/json' ,
16
+ } ;
17
+
18
+ const masterKeyOptions = {
19
+ headers : masterKeyHeaders ,
20
+ json : true ,
21
+ } ;
22
+
23
+ describe_only_db ( 'mongo' ) ( 'Parse.Query with comment testing' , ( ) => {
11
24
beforeEach ( async ( ) => {
12
25
config = Config . get ( 'test' ) ;
13
26
client = await MongoClient . connect ( databaseURI , {
@@ -24,17 +37,63 @@ describe_only_db('mongo')('Parse.Query testing', () => {
24
37
await client . close ( ) ;
25
38
await TestUtils . destroyAllDataPermanently ( false ) ;
26
39
} ) ;
40
+
41
+ it ( 'send comment with query through REST' , async ( ) => {
42
+ const comment = 'Hello Parse' ;
43
+ const options = Object . assign ( { } , masterKeyOptions , {
44
+ url : Parse . serverURL + '/classes/TestObject' ,
45
+ qs : {
46
+ explain : true ,
47
+ comment : comment ,
48
+ } ,
49
+ } ) ;
50
+ const response = await request ( options ) ;
51
+ let result = response . data . results ;
52
+ expect ( result . command . comment ) . toBe ( comment ) ;
53
+ result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
54
+ expect ( result . command . comment ) . toBe ( comment ) ;
55
+ } ) ;
56
+
27
57
it ( 'send comment with query' , async ( ) => {
58
+ const comment = 'Hello Parse' ;
28
59
const object = new TestObject ( ) ;
29
60
object . set ( 'name' , 'object' ) ;
30
- const comment = 'comment' ;
31
61
await object . save ( ) ;
32
-
33
62
const collection = await config . database . adapter . _adaptiveCollection ( 'TestObject' ) ;
34
-
35
63
await collection . _rawFind ( { name : 'object' } , { comment : comment } ) ;
64
+ const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
65
+ expect ( result . command . comment ) . toBe ( comment ) ;
66
+ } ) ;
36
67
68
+ it ( 'send a comment with a count query' , async ( ) => {
69
+ const comment = 'Hello Parse' ;
70
+ const object = new TestObject ( ) ;
71
+ object . set ( 'name' , 'object' ) ;
72
+ await object . save ( ) ;
73
+
74
+ const object2 = new TestObject ( ) ;
75
+ object2 . set ( 'name' , 'object' ) ;
76
+ await object2 . save ( ) ;
77
+
78
+ const collection = await config . database . adapter . _adaptiveCollection ( 'TestObject' ) ;
79
+ const countResult = await collection . count ( { name : 'object' } , { comment : comment } ) ;
80
+ expect ( countResult ) . toEqual ( 2 ) ;
37
81
const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
38
82
expect ( result . command . comment ) . toBe ( comment ) ;
39
83
} ) ;
84
+
85
+ it ( 'attach a comment to an aggregation' , async ( ) => {
86
+ const comment = 'Hello Parse' ;
87
+ const object = new TestObject ( ) ;
88
+ object . set ( 'name' , 'object' ) ;
89
+ await object . save ( ) ;
90
+ const collection = await config . database . adapter . _adaptiveCollection ( 'TestObject' ) ;
91
+ let result = await collection . aggregate ( [ { $group : { _id : '$name' } } ] , {
92
+ explain : true ,
93
+ comment : comment ,
94
+ } ) ;
95
+ expect ( result [ 0 ] . command . comment ) . toBe ( comment ) ;
96
+ result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
97
+ expect ( result . command . comment ) . toBe ( comment ) ;
98
+ } ) ;
40
99
} ) ;
0 commit comments