Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"babel-polyfill": "6.8.0",
"babel-runtime": "6.6.1",
"bcrypt-nodejs": "0.0.3",
"bluebird": "^3.4.6",
"body-parser": "1.15.2",
"colors": "1.1.2",
"commander": "2.9.0",
Expand Down
291 changes: 291 additions & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,4 +1462,295 @@ describe('miscellaneous', function() {
done();
});
});

it_exclude_dbs(['postgres'])('import objects from rest array', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify([
{ column1: 'row1Column1', column2: 'row1Column2' },
{ column1: 'row2Column1', column2: 'row2Column2' }
])
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObject');
query.ascending('column1');
query.find().then((results) => {
expect(results.length).toEqual(2);
expect(results[0].get('column1')).toEqual('row1Column1');
expect(results[0].get('column2')).toEqual('row1Column2');
expect(results[1].get('column1')).toEqual('row2Column1');
expect(results[1].get('column2')).toEqual('row2Column2');
done();
});
}
);
});

it_exclude_dbs(['postgres'])('import objects from json with results field', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify({
results: [
{ column1: 'row1Column1', column2: 'row1Column2' },
{ column1: 'row2Column1', column2: 'row2Column2' }
]
})
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObject');
query.ascending('column1');
query.find().then((results) => {
expect(results.length).toEqual(2);
expect(results[0].get('column1')).toEqual('row1Column1');
expect(results[0].get('column2')).toEqual('row1Column2');
expect(results[1].get('column1')).toEqual('row2Column1');
expect(results[1].get('column2')).toEqual('row2Column2');
done();
});
}
);
});

it_exclude_dbs(['postgres'])('import objects with all data types', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify({
results: [
{
boolColumnTrue: true,
boolColumnFalse: false,
stringColumn: 'stringColumnValue',
numberColumn: 100.1,
dateColumn: {
"__type": "Date",
"iso": "2016-10-30T12:03:56.848Z"
},
arrayColumn: [
1,
2,
3
],
objectColumn: {
'key': 'value'
},
geoColumn: {
"__type": "GeoPoint",
"latitude": 10,
"longitude": -10
},
fileColumn: {
"__type": "File",
"name": "myfile.png",
"url": "http://myhost.com/myfile.png"
},
pointerColumn: {
"__type": "Pointer",
"className": "_User",
"objectId": "AAAAAAAAAA"
}
}
]
})
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObject');
query.ascending('column1');
query.find().then((results) => {
expect(results.length).toEqual(1);
expect(results[0].get('stringColumn')).toEqual('stringColumnValue');
done();
});
}
);
});

it_exclude_dbs(['postgres'])('import objects with object id', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify({
results: [
{
'objectId': 'aaaaaaaaaa',
'data': 'somedataa'
},
{
'objectId': 'bbbbbbbbbb',
'data': 'somedatab'
}
]
})
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObject');
query.ascending('data');
query.find().then((results) => {
expect(results.length).toEqual(2);
expect(results[0].id).toEqual('aaaaaaaaaa');
expect(results[1].id).toEqual('bbbbbbbbbb');
done();
});
}
);
});

it_exclude_dbs(['postgres'])('update objects with existing object id', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify({
results: [
{
'objectId': 'aaaaaaaaaa',
'data': 'somedataa'
},
{
'objectId': 'bbbbbbbbbb',
'data': 'somedatab'
}
]
})
},
(err) => {
expect(err).toBe(null);
request.post(
{
headers: headers,
url: 'http://localhost:8378/1/import/TestObject',
body: JSON.stringify({
results: [
{
'objectId': 'aaaaaaaaaa',
'data': 'somedataa2'
}
]
})
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObject');
query.ascending('data');
query.find().then((results) => {
expect(results.length).toEqual(2);
expect(results[0].id).toEqual('aaaaaaaaaa');
expect(results[0].get('data')).toEqual('somedataa2');
expect(results[1].id).toEqual('bbbbbbbbbb');
expect(results[1].get('data')).toEqual('somedatab');
done();
});
}
);
}
);
});

it_exclude_dbs(['postgres'])('import relations object from json', (done) => {
let headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};

let promises = [];

let object = new Parse.Object('TestObjectDad');
let relatedObject = new Parse.Object('TestObjectChild');
Parse.Object.saveAll([object, relatedObject]).then(() => {
object.relation('RelationObject').add(relatedObject);
return object.save();
});

promises.push(rp({
method: 'POST',
headers: headers,
url: 'http://localhost:8378/1/import/TestObjectDad',
body: JSON.stringify({
results: [
{
'objectId': 'aaa',
'Name': 'namea',
}
]
})
}));

promises.push(rp({
method: 'POST',
headers: headers,
url: 'http://localhost:8378/1/import/TestObjectChild',
body: JSON.stringify({
results: [
{
'objectId': 'bbb',
'Name': 'nameb'
}
]
})
}));

Promise.all(promises).then(() => {
rp(
{
method: 'POST',
headers: headers,
url: 'http://localhost:8378/1/import/TestObjectDad/RelationObject',
body: JSON.stringify({
results: [
{
'owningId': 'aaa',
'relatedId': 'bbb'
}
]
})
},
(err) => {
expect(err).toBe(null);
let query = new Parse.Query('TestObjectDad');
query._where = {'RelationObject':{'__type':'Pointer', 'className':'TestObjectChild', 'objectId':'bbb'}};
query.find().then((results) => {
expect(results.length).toEqual(1);
expect(results[0].id).toEqual('aaa');
done();
});
}
)
});
});
});
4 changes: 4 additions & 0 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import { SessionsRouter } from './Routers/SessionsRouter';
import { UserController } from './Controllers/UserController';
import { UsersRouter } from './Routers/UsersRouter';
import { PurgeRouter } from './Routers/PurgeRouter';
import { ImportRouter } from './Routers/ImportRouter';
import { ImportRelationRouter } from './Routers/ImportRelationRouter';

import DatabaseController from './Controllers/DatabaseController';
const SchemaController = require('./Controllers/SchemaController');
Expand Down Expand Up @@ -300,6 +302,8 @@ class ParseServer {
new FeaturesRouter(),
new GlobalConfigRouter(),
new PurgeRouter(),
new ImportRouter(),
new ImportRelationRouter(),
];

if (process.env.PARSE_EXPERIMENTAL_HOOKS_ENABLED || process.env.TESTING) {
Expand Down
5 changes: 3 additions & 2 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import _ from 'lodash';
// RestWrite will handle objectId, createdAt, and updatedAt for
// everything. It also knows to use triggers and special modifications
// for the _User class.
function RestWrite(config, auth, className, query, data, originalData) {
function RestWrite(config, auth, className, query, data, originalData, clientSDK, options) {
this.config = config;
this.auth = auth;
this.className = className;
this.storage = {};
this.runOptions = {};

if (!query && data.objectId) {
let allowObjectId = options && options.allowObjectId === true;
if (!query && data.objectId && !allowObjectId) {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'objectId is an invalid field name.');
}

Expand Down
Loading