Skip to content

Commit

Permalink
Fix conflicting test
Browse files Browse the repository at this point in the history
  • Loading branch information
davimacedo committed Oct 4, 2019
1 parent 762a279 commit 4f8e6df
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 37 deletions.
54 changes: 54 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,60 @@ describe('Cloud Code', () => {
expect(called).toBe(7);
});

fit('afterFind should not be triggered when saving an object', async () => {
let beforeSaves = 0;
Parse.Cloud.beforeSave('SavingTest', () => {
beforeSaves++;
});

let afterSaves = 0;
Parse.Cloud.afterSave('SavingTest', () => {
afterSaves++;
});

let beforeFinds = 0;
Parse.Cloud.beforeFind('SavingTest', () => {
beforeFinds++;
});

let afterFinds = 0;
Parse.Cloud.afterFind('SavingTest', () => {
afterFinds++;
});

const obj = new Parse.Object('SavingTest');
obj.set('someField', 'some value 1');
await obj.save();

expect(beforeSaves).toEqual(1);
expect(afterSaves).toEqual(1);
expect(beforeFinds).toEqual(0);
expect(afterFinds).toEqual(0);

obj.set('someField', 'some value 2');
await obj.save();

expect(beforeSaves).toEqual(2);
expect(afterSaves).toEqual(2);
expect(beforeFinds).toEqual(0);
expect(afterFinds).toEqual(0);

await obj.fetch();

expect(beforeSaves).toEqual(2);
expect(afterSaves).toEqual(2);
expect(beforeFinds).toEqual(1);
expect(afterFinds).toEqual(1);

obj.set('someField', 'some value 3');
await obj.save();

expect(beforeSaves).toEqual(3);
expect(afterSaves).toEqual(3);
expect(beforeFinds).toEqual(1);
expect(afterFinds).toEqual(1);
});

it('test afterSave ran and created an object', function(done) {
Parse.Cloud.afterSave('AfterSaveTest', function(req) {
const obj = new Parse.Object('AfterSaveProof');
Expand Down
80 changes: 43 additions & 37 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7634,22 +7634,25 @@ describe('ParseGraphQLServer', () => {
} = await apolloClient.mutate({
mutation: gql`
mutation Create($fields: CreateSomeClassFieldsInput) {
createSomeClass(fields: $fields) {
id
ACL {
users {
userId
read
write
}
roles {
roleName
read
write
}
public {
read
write
createSomeClass(input: { fields: $fields }) {
someClass {
id
objectId
ACL {
users {
userId
read
write
}
roles {
roleName
read
write
}
public {
read
write
}
}
}
}
Expand Down Expand Up @@ -7705,44 +7708,47 @@ describe('ParseGraphQLServer', () => {
public: { read: true, write: true, __typename: 'PublicACL' },
};
const query1 = new Parse.Query('SomeClass');
const obj1 = (await query1.get(createSomeClass.id, {
const obj1 = (await query1.get(createSomeClass.someClass.objectId, {
useMasterKey: true,
})).toJSON();
expect(obj1.ACL[user.id]).toEqual({ read: true, write: true });
expect(obj1.ACL[user2.id]).toEqual({ read: true });
expect(obj1.ACL['role:aRole']).toEqual({ read: true });
expect(obj1.ACL['role:aRole2']).toEqual({ write: true });
expect(obj1.ACL['*']).toEqual({ read: true, write: true });
expect(createSomeClass.ACL).toEqual(expectedCreateACL);
expect(createSomeClass.someClass.ACL).toEqual(expectedCreateACL);

const {
data: { updateSomeClass },
} = await apolloClient.mutate({
mutation: gql`
mutation Update($id: ID!, $fields: UpdateSomeClassFieldsInput) {
updateSomeClass(id: $id, fields: $fields) {
id
ACL {
users {
userId
read
write
}
roles {
roleName
read
write
}
public {
read
write
updateSomeClass(input: { id: $id, fields: $fields }) {
someClass {
id
objectId
ACL {
users {
userId
read
write
}
roles {
roleName
read
write
}
public {
read
write
}
}
}
}
}
`,
variables: {
id: createSomeClass.id,
id: createSomeClass.someClass.id,
fields: {
ACL: {
roles: [{ roleName: 'aRole', write: true, read: true }],
Expand All @@ -7767,14 +7773,14 @@ describe('ParseGraphQLServer', () => {
};

const query2 = new Parse.Query('SomeClass');
const obj2 = (await query2.get(createSomeClass.id, {
const obj2 = (await query2.get(createSomeClass.someClass.objectId, {
useMasterKey: true,
})).toJSON();

expect(obj2.ACL['role:aRole']).toEqual({ write: true, read: true });
expect(obj2.ACL[user.id]).toBeUndefined();
expect(obj2.ACL['*']).toEqual({ read: true });
expect(updateSomeClass.ACL).toEqual(expectedUpdateACL);
expect(updateSomeClass.someClass.ACL).toEqual(expectedUpdateACL);
});

it('should support pointer on create', async () => {
Expand Down

0 comments on commit 4f8e6df

Please sign in to comment.