Remove all dependencies on schemaController

This commit is contained in:
Drew Gross
2016-05-23 16:43:51 -07:00
parent d944255e4e
commit f4b1f7b951
2 changed files with 20 additions and 12 deletions

View File

@@ -153,7 +153,9 @@ describe('mongoObjectToParseObject', () => {
it('file', (done) => { it('file', (done) => {
var input = {picture: 'pic.jpg'}; var input = {picture: 'pic.jpg'};
var output = transform.mongoObjectToParseObject(dummySchema, null, input); var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
fields: { picture: { type: 'File' }},
});
expect(typeof output.picture).toEqual('object'); expect(typeof output.picture).toEqual('object');
expect(output.picture).toEqual({__type: 'File', name: 'pic.jpg'}); expect(output.picture).toEqual({__type: 'File', name: 'pic.jpg'});
done(); done();
@@ -161,7 +163,9 @@ describe('mongoObjectToParseObject', () => {
it('geopoint', (done) => { it('geopoint', (done) => {
var input = {location: [180, -180]}; var input = {location: [180, -180]};
var output = transform.mongoObjectToParseObject(dummySchema, null, input); var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
fields: { location: { type: 'GeoPoint' }},
});
expect(typeof output.location).toEqual('object'); expect(typeof output.location).toEqual('object');
expect(output.location).toEqual( expect(output.location).toEqual(
{__type: 'GeoPoint', longitude: 180, latitude: -180} {__type: 'GeoPoint', longitude: 180, latitude: -180}
@@ -171,7 +175,9 @@ describe('mongoObjectToParseObject', () => {
it('nested array', (done) => { it('nested array', (done) => {
var input = {arr: [{_testKey: 'testValue' }]}; var input = {arr: [{_testKey: 'testValue' }]};
var output = transform.mongoObjectToParseObject(dummySchema, null, input); var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
fields: { arr: { type: 'Array' } },
});
expect(Array.isArray(output.arr)).toEqual(true); expect(Array.isArray(output.arr)).toEqual(true);
expect(output.arr).toEqual([{ _testKey: 'testValue'}]); expect(output.arr).toEqual([{ _testKey: 'testValue'}]);
done(); done();
@@ -189,7 +195,9 @@ describe('mongoObjectToParseObject', () => {
}, },
regularKey: "some data", regularKey: "some data",
}]} }]}
let output = transform.mongoObjectToParseObject(dummySchema, null, input); let output = transform.mongoObjectToParseObject(dummySchema, null, input, {
fields: { array: { type: 'Array' }},
});
expect(dd(output, input)).toEqual(undefined); expect(dd(output, input)).toEqual(undefined);
done(); done();
}); });
@@ -271,7 +279,12 @@ describe('transform schema key changes', () => {
long: mongodb.Long.fromNumber(Number.MAX_SAFE_INTEGER), long: mongodb.Long.fromNumber(Number.MAX_SAFE_INTEGER),
double: new mongodb.Double(Number.MAX_VALUE) double: new mongodb.Double(Number.MAX_VALUE)
} }
var output = transform.mongoObjectToParseObject(dummySchema, null, input); var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
fields: {
long: { type: 'Number' },
double: { type: 'Number' },
},
});
expect(output.long).toBe(Number.MAX_SAFE_INTEGER); expect(output.long).toBe(Number.MAX_SAFE_INTEGER);
expect(output.double).toBe(Number.MAX_VALUE); expect(output.double).toBe(Number.MAX_VALUE);
done(); done();

View File

@@ -830,10 +830,6 @@ const mongoObjectToParseObject = (schemaController, className, mongoObject, sche
if (key.indexOf('_p_') == 0) { if (key.indexOf('_p_') == 0) {
var newKey = key.substring(3); var newKey = key.substring(3);
var expected;
if (schemaController && schemaController.getExpectedType) {
expected = schemaController.getExpectedType(className, newKey);
}
if (!schema.fields[newKey]) { if (!schema.fields[newKey]) {
log.info('transform.js', 'Found a pointer column not in the schema, dropping it.', className, newKey); log.info('transform.js', 'Found a pointer column not in the schema, dropping it.', className, newKey);
break; break;
@@ -858,13 +854,12 @@ const mongoObjectToParseObject = (schemaController, className, mongoObject, sche
} else if (key[0] == '_' && key != '__type') { } else if (key[0] == '_' && key != '__type') {
throw ('bad key in untransform: ' + key); throw ('bad key in untransform: ' + key);
} else { } else {
var expectedType = schemaController.getExpectedType(className, key);
var value = mongoObject[key]; var value = mongoObject[key];
if (expectedType && expectedType.type === 'File' && FileCoder.isValidDatabaseObject(value)) { if (schema.fields[key] && schema.fields[key].type === 'File' && FileCoder.isValidDatabaseObject(value)) {
restObject[key] = FileCoder.databaseToJSON(value); restObject[key] = FileCoder.databaseToJSON(value);
break; break;
} }
if (expectedType && expectedType.type === 'GeoPoint' && GeoPointCoder.isValidDatabaseObject(value)) { if (schema.fields[key] && schema.fields[key].type === 'GeoPoint' && GeoPointCoder.isValidDatabaseObject(value)) {
restObject[key] = GeoPointCoder.databaseToJSON(value); restObject[key] = GeoPointCoder.databaseToJSON(value);
break; break;
} }