Fixing #1900 JS SDK file upload (#1935)

* Fixing #1900 JS SDK file upload

JS SDK file upload uses req.body._ContentType to specify the upload content type

* Fixing import statements

* Dont clear the cache just delete the new entry that the test added.

* adding E2E test for _ContentType support
This commit is contained in:
Blayne Chard
2016-05-31 13:42:45 +12:00
committed by Florent Vilmart
parent cd525802a6
commit 3997b1aa5a
3 changed files with 96 additions and 0 deletions

67
spec/Middlewares.spec.js Normal file
View File

@@ -0,0 +1,67 @@
var middlewares = require('../src/middlewares');
var AppCache = require('../src/cache').AppCache;
describe('middlewares', () => {
var fakeReq, fakeRes;
beforeEach(() => {
fakeReq = {
originalUrl: 'http://example.com/parse/',
url: 'http://example.com/',
body: {
_ApplicationId: 'FakeAppId'
},
headers: {},
get: (key) => {
return fakeReq.headers[key.toLowerCase()]
}
};
AppCache.put(fakeReq.body._ApplicationId, {});
});
afterEach(() => {
AppCache.del(fakeReq.body._ApplicationId);
});
it('should use _ContentType if provided', (done) => {
expect(fakeReq.headers['content-type']).toEqual(undefined);
fakeReq.body._ContentType = 'image/jpeg';
middlewares.handleParseHeaders(fakeReq, fakeRes, () => {
expect(fakeReq.headers['content-type']).toEqual(fakeReq.body._ContentType);
done()
});
});
const BodyParams = {
clientVersion: '_ClientVersion',
installationId: '_InstallationId',
sessionToken: '_SessionToken',
masterKey: '_MasterKey',
javascriptKey: '_JavaScriptKey'
};
const BodyKeys = Object.keys(BodyParams);
BodyKeys.forEach((infoKey) => {
const bodyKey = BodyParams[infoKey];
const keyValue = 'Fake' + bodyKey;
// javascriptKey is the only one that gets defaulted,
const otherKeys = BodyKeys.filter((otherKey) => otherKey !== infoKey && otherKey !== 'javascriptKey');
it(`it should pull ${bodyKey} into req.info`, (done) => {
fakeReq.body[bodyKey] = keyValue;
middlewares.handleParseHeaders(fakeReq, fakeRes, () => {
expect(fakeReq.body[bodyKey]).toEqual(undefined);
expect(fakeReq.info[infoKey]).toEqual(keyValue);
otherKeys.forEach((otherKey) => {
expect(fakeReq.info[otherKey]).toEqual(undefined);
});
done();
});
});
});
});