From 80b987d00d8eda89f1ee521103c4737b64c66cc1 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Wed, 25 Oct 2023 20:32:58 +0200 Subject: [PATCH] test: Improve test for `$setOnInsert` (#8793) --- spec/MongoStorageAdapter.spec.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/spec/MongoStorageAdapter.spec.js b/spec/MongoStorageAdapter.spec.js index 29a97b2ddb..25a6ae5639 100644 --- a/spec/MongoStorageAdapter.spec.js +++ b/spec/MongoStorageAdapter.spec.js @@ -258,6 +258,19 @@ describe_only_db('mongo')('MongoStorageAdapter', () => { const uuid = require('uuid'); const uuid1 = uuid.v4(); const uuid2 = uuid.v4(); + const schema = { + className: 'MyClass', + fields: { + x: { type: 'Number' }, + count: { type: 'Number' }, + }, + classLevelPermissions: {}, + }; + + const myClassSchema = new Parse.Schema(schema.className); + myClassSchema.setCLP(schema.classLevelPermissions); + await myClassSchema.save(); + const query = { x: 1, }; @@ -266,7 +279,6 @@ describe_only_db('mongo')('MongoStorageAdapter', () => { __op: 'SetOnInsert', amount: uuid1, }, - x: 1, count: { __op: 'Increment', amount: 1, @@ -285,12 +297,16 @@ describe_only_db('mongo')('MongoStorageAdapter', () => { update, { upsert: true }, ); - const q = new Parse.Query('MyClass'); - const docs = await q.find(); - expect(docs.length).toBe(1); - expect(docs[0].id).toBe(uuid1); - expect(docs[0].get('x')).toBe(1); - expect(docs[0].get('count')).toBe(2); + + const res = await Parse.Server.database.find( + schema.className, + {}, + {}, + ); + expect(res.length).toBe(1); + expect(res[0].objectId).toBe(uuid1); + expect(res[0].count).toBe(2); + expect(res[0].x).toBe(1); }); it('handles updating a single object with array, object date', done => {