Skip to content
Merged
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
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
],
"presets": [
"es2015",
"stage-0"
"stage-3",
["env", {
"targets": {
"node": "4.6"
}
}]
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
"babel-eslint": "^7.1.1",
"babel-plugin-syntax-flow": "6.18.0",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"babel-preset-env": "1.6.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"babel-preset-stage-3": "6.24.1",
"babel-register": "6.26.0",
"bcrypt-nodejs": "0.0.3",
"cross-env": "5.0.2",
Expand Down
6 changes: 6 additions & 0 deletions spec/CLI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ describe('definitions', () => {
}
}
});

it('should throw when using deprecated facebookAppIds', () => {
expect(() => {
definitions.facebookAppIds.action()
}).toThrow();
});
});

describe('LiveQuery definitions', () => {
Expand Down
286 changes: 286 additions & 0 deletions spec/ParseFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,290 @@ describe('Parse.File testing', () => {
done();
});
});

it('fails to upload an empty file', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: '',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":130,"error":"Invalid file upload."}');
done();
});
});

it('fails to upload without a file name', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/',
body: 'yolo',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":122,"error":"Filename not provided."}');
done();
});
});

it('fails to upload without a file name', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/',
body: 'yolo',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":122,"error":"Filename not provided."}');
done();
});
});

it('fails to delete an unkown file', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'X-Parse-Master-Key': 'test'
};
request.delete({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":153,"error":"Could not delete file."}');
done();
});
});

describe_only_db('mongo')('Gridstore Range tests', () => {
it('supports range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-5'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('argle ');
done();
});
});
});

it('supports small range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-2'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('arg');
done();
});
});
});

// See specs https://www.greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-latest.html#byte.ranges
it('supports getting one byte', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=2-2'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('g');
done();
});
});
});

it('supports getting last n bytes', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'something different',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=-4'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body.length).toBe(4);
expect(body).toEqual('rent');
done();
});
});
});

it('supports getting first n bytes', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'something different',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=10-'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('different');
done();
});
});
});

function repeat(string, count) {
var s = string;
while (count > 0) {
s += string;
count--;
}
return s;
}

it('supports large range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: repeat('argle bargle', 100)
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=13-240'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body.length).toEqual(228);
expect(body.indexOf('rgle barglea')).toBe(0);
done();
});
});
});

it('fails to stream unknown file', done => {
request.get({ url: 'http://localhost:8378/1/files/test/file.txt', headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=13-240'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(404);
expect(body).toEqual('File not found.');
done();
});
});
});

// Because GridStore is not loaded on PG, those are perfect
// for fallback tests
describe_only_db('postgres')('Default Range tests', () => {
it('fallback to regular request', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-5'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('argle bargle');
done();
});
});
});
});
});
33 changes: 33 additions & 0 deletions spec/parsers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
numberParser,
numberOrBoolParser,
booleanParser,
objectParser,
arrayParser,
moduleOrObjectParser,
nullParser,
} from '../src/cli/utils/parsers';

describe('parsers', () => {
Expand Down Expand Up @@ -31,4 +35,33 @@ describe('parsers', () => {
expect(parser(1)).toEqual(true);
expect(parser(2)).toEqual(false);
});

it('parses correctly with objectParser', () => {
const parser = objectParser;
expect(parser({hello: 'world'})).toEqual({hello: 'world'});
expect(parser('{"hello": "world"}')).toEqual({hello: 'world'});
expect(() => {parser('string')}).toThrow();
});

it('parses correctly with moduleOrObjectParser', () => {
const parser = moduleOrObjectParser;
expect(parser({hello: 'world'})).toEqual({hello: 'world'});
expect(parser('{"hello": "world"}')).toEqual({hello: 'world'});
expect(parser('string')).toEqual('string');
});

it('parses correctly with arrayParser', () => {
const parser = arrayParser;
expect(parser([1,2,3])).toEqual([1,2,3]);
expect(parser('{"hello": "world"}')).toEqual(['{"hello": "world"}']);
expect(parser('1,2,3')).toEqual(['1','2','3']);
expect(() => {parser(1)}).toThrow();
});

it('parses correctly with nullParser', () => {
const parser = nullParser;
expect(parser('null')).toEqual(null);
expect(parser(1)).toEqual(1);
expect(parser('blabla')).toEqual('blabla');
});
});
4 changes: 0 additions & 4 deletions src/Adapters/Storage/Mongo/MongoCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export default class MongoCollection {
return this._mongoCollection.updateMany(query, update);
}

deleteOne(query) {
return this._mongoCollection.deleteOne(query);
}

deleteMany(query) {
return this._mongoCollection.deleteMany(query);
}
Expand Down
Loading