support Relation object saving (#3074)

* support Parse.Relation object save

* prevent Relation object from being saved in storage
This commit is contained in:
Yuki Takeichi
2016-11-20 23:00:34 +09:00
committed by Florent Vilmart
parent e9e6a4764e
commit 4ea455b20a
5 changed files with 84 additions and 1 deletions

View File

@@ -236,6 +236,19 @@ describe('parseObjectToMongoObjectForCreate', () => {
done();
});
it('removes Relation types', (done) => {
var input = {
aRelation: { __type: 'Relation', className: 'Stuff' },
};
var output = transform.parseObjectToMongoObjectForCreate(null, input, {
fields: {
aRelation: { __type: 'Relation', className: 'Stuff' },
},
});
expect(output).toEqual({});
done();
});
it('writes the old ACL format in addition to rperm and wperm on update', (done) => {
var input = {
_rperm: ['*'],
@@ -280,5 +293,19 @@ describe('parseObjectToMongoObjectForCreate', () => {
expect(output.double).toBe(Number.MAX_VALUE);
done();
});
});
describe('transformUpdate', () => {
it('removes Relation types', (done) => {
var input = {
aRelation: { __type: 'Relation', className: 'Stuff' },
};
var output = transform.transformUpdate(null, input, {
fields: {
aRelation: { __type: 'Relation', className: 'Stuff' },
},
});
expect(output).toEqual({});
done();
});
});

View File

@@ -741,4 +741,32 @@ describe('Parse.Relation testing', () => {
done();
});
});
it('can be saved without error', done => {
let obj1 = new Parse.Object('PPAP');
obj1.save()
.then(() => {
let newRelation = obj1.relation('aRelation');
newRelation.add(obj1);
obj1.save().then(() => {
let relation = obj1.get('aRelation');
obj1.set('aRelation', relation);
obj1.save().then(() => {
done();
}, error => {
fail('failed to save ParseRelation object');
fail(error);
done();
});
}, error => {
fail('failed to create relation field');
fail(error);
done();
});
}, error => {
fail('failed to save obj');
fail(error);
done();
});
});
});

View File

@@ -56,6 +56,21 @@ describe('SchemaController', () => {
});
});
it('can validate Relation object', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('Stuff', {aRelation: {__type:'Relation',className:'Stuff'}});
}).then((schema) => {
return schema.validateObject('Stuff', {aRelation: {__type:'Pointer',className:'Stuff'}})
.then((schema) => {
fail('expected invalidity');
done();
}, done);
}, (err) => {
fail(err);
done();
});
});
it('rejects inconsistent types', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('Stuff', {bacon: 7});