Skip to content

Commit 34494ad

Browse files
committed
test: Add rawFieldNames coverage for name preservation on input and output
1 parent 40587d7 commit 34494ad

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

spec/ParseQuery.Aggregate.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,4 +1675,43 @@ describe('Parse.Query Aggregate testing', () => {
16751675
expect(results.length).toBe(1);
16761676
expect(results[0].total).toBe(1);
16771677
});
1678+
1679+
it_id('f01a0002-0002-0002-0002-000000000002')(it_exclude_dbs(['postgres']))('rawFieldNames: true does NOT rewrite Parse-style names', async () => {
1680+
const obj = new TestObject();
1681+
await obj.save();
1682+
const iso = new Date(obj.createdAt.getTime() + 1).toISOString();
1683+
// Using Parse-style `createdAt` under rawFieldNames should query a field that doesn't exist in MongoDB.
1684+
const pipeline = [
1685+
{ $match: { _id: obj.id, createdAt: { $lte: { $date: iso } } } },
1686+
{ $count: 'total' },
1687+
];
1688+
const query = new Parse.Query('TestObject');
1689+
const results = await query.aggregate(pipeline, {
1690+
rawValues: true,
1691+
rawFieldNames: true,
1692+
useMasterKey: true,
1693+
});
1694+
// `createdAt` is not a MongoDB field name; no documents match.
1695+
expect(results.length).toBe(0);
1696+
});
1697+
1698+
it_id('f01a0002-0003-0003-0003-000000000003')(it_exclude_dbs(['postgres']))('rawFieldNames: true returns native field names in results', async () => {
1699+
const obj = new TestObject();
1700+
await obj.save();
1701+
const pipeline = [
1702+
{ $match: { _id: obj.id } },
1703+
{ $project: { _id: 1, _created_at: 1 } },
1704+
];
1705+
const query = new Parse.Query('TestObject');
1706+
const results = await query.aggregate(pipeline, {
1707+
rawValues: true,
1708+
rawFieldNames: true,
1709+
useMasterKey: true,
1710+
});
1711+
expect(results.length).toBe(1);
1712+
expect(results[0]._id).toBe(obj.id);
1713+
expect(Object.prototype.hasOwnProperty.call(results[0], '_created_at')).toBe(true);
1714+
expect(Object.prototype.hasOwnProperty.call(results[0], 'objectId')).toBe(false);
1715+
expect(Object.prototype.hasOwnProperty.call(results[0], 'createdAt')).toBe(false);
1716+
});
16781717
});

0 commit comments

Comments
 (0)