Skip to content

Commit b7d3e55

Browse files
committed
added more tests
1 parent 66c778d commit b7d3e55

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

spec/ParseQuery.Comment.spec.js

+63-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ const Config = require('../lib/Config');
44
const TestUtils = require('../lib/TestUtils');
55
const { MongoClient } = require('mongodb');
66
const databaseURI = 'mongodb://localhost:27017/';
7+
const request = require('../lib/request');
78

89
let config, client, database;
910

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', () => {
1124
beforeEach(async () => {
1225
config = Config.get('test');
1326
client = await MongoClient.connect(databaseURI, {
@@ -24,17 +37,63 @@ describe_only_db('mongo')('Parse.Query testing', () => {
2437
await client.close();
2538
await TestUtils.destroyAllDataPermanently(false);
2639
});
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+
2757
it('send comment with query', async () => {
58+
const comment = 'Hello Parse';
2859
const object = new TestObject();
2960
object.set('name', 'object');
30-
const comment = 'comment';
3161
await object.save();
32-
3362
const collection = await config.database.adapter._adaptiveCollection('TestObject');
34-
3563
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+
});
3667

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);
3781
const result = await database.collection('system.profile').findOne({}, { sort: { ts: -1 } });
3882
expect(result.command.comment).toBe(comment);
3983
});
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+
});
4099
});

0 commit comments

Comments
 (0)