Skip to content

Commit b196349

Browse files
committed
Adds failing test for the issue
1 parent bb16414 commit b196349

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec/ParseRelation.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,38 @@ describe('Parse.Relation testing', () => {
801801
done();
802802
});
803803
});
804+
805+
it('ensures beforeFind on relation doesnt side effect', (done) => {
806+
const parent = new Parse.Object('Parent');
807+
const child = new Parse.Object('Child');
808+
child.save().then(() => {
809+
parent.relation('children').add(child);
810+
return parent.save();
811+
}).then(() => {
812+
// We need to use a new reference otherwise the JS SDK remembers the className for a relation
813+
// After saves or finds
814+
const otherParent = new Parse.Object('Parent');
815+
otherParent.id = parent.id;
816+
return otherParent.relation('children').query().find();
817+
}).then((children) => {
818+
// Without an after find all is good, all results have been redirected with proper className
819+
children.forEach((child) => expect(child.className).toBe('Child'));
820+
// Setup the afterFind
821+
Parse.Cloud.afterFind('Child', (req) => {
822+
return Promise.resolve(req.objects.map((child) => {
823+
child.set('afterFound', true);
824+
return child;
825+
}));
826+
});
827+
const otherParent = new Parse.Object('Parent');
828+
otherParent.id = parent.id;
829+
return otherParent.relation('children').query().find();
830+
}).then((children) => {
831+
children.forEach((child) => {
832+
833+
expect(child.className).toBe('Child');
834+
expect(child.get('afterFound')).toBe(true);
835+
});
836+
}).then(done).catch(done.fail);
837+
});
804838
});

0 commit comments

Comments
 (0)