Skip to content

Commit

Permalink
test: Improve test for $setOnInsert (parse-community#8793)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza authored Oct 25, 2023
1 parent 9e00949 commit 80b987d
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -266,7 +279,6 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
__op: 'SetOnInsert',
amount: uuid1,
},
x: 1,
count: {
__op: 'Increment',
amount: 1,
Expand All @@ -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 => {
Expand Down

0 comments on commit 80b987d

Please sign in to comment.