Uses rawCollection() for direct db access

Updated tests accordingly to changed access
This commit is contained in:
Peter Theill
2016-02-09 00:36:45 +01:00
parent 7733ab9625
commit 8b3f8751f4
5 changed files with 83 additions and 59 deletions

View File

@@ -1,47 +1,61 @@
var auth = require('../Auth');
var cache = require('../cache');
var Config = require('../Config');
var request = require('request');
var DatabaseAdapter = require('../DatabaseAdapter');
var Parse = require('parse/node').Parse;
var rest = require('../rest');
var config = new Config('test');
var database = DatabaseAdapter.getDatabaseConnection('test');
describe('GlobalConfig', () => {
beforeEach(function() {
database.create('_GlobalConfig', { objectId: 1, params: { mostValuableCompany: 'Apple' } }, {});
describe('a GlobalConfig', () => {
beforeEach(function(done) {
database.rawCollection('_GlobalConfig')
.then(coll => coll.updateOne({ '_id': 1}, { $set: { params: { companies: ['US', 'DK'] } } }, { upsert: true }))
.then(done());
});
it('find existing values', (done) => {
rest.find(config, auth.nobody(config), '_GlobalConfig', 1)
.then(() => {
return database.mongoFind('_GlobalConfig', {}, {});
}).then((results) => {
expect(results.length).toEqual(1);
var obj = results[0];
expect(obj.params.mostValuableCompany).toEqual('Apple');
it('can be retrieved', (done) => {
request.get({
url: 'http://localhost:8378/1/config',
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.params.companies).toEqual(['US', 'DK']);
done();
}).catch((error) => { console.log(error); });
});
});
it('update with a new value', (done) => {
var input = {
params: {
mostValuableCompany: 'Alphabet'
}
};
rest.update(config, auth.nobody(config), '_GlobalConfig', 1, input)
.then(() => {
return database.mongoFind('_GlobalConfig', {}, {});
}).then((results) => {
expect(results.length).toEqual(1);
var obj = results[0];
expect(obj.params.mostValuableCompany).toEqual('Alphabet');
it('can be updated when a master key exists', (done) => {
request.post({
url: 'http://localhost:8378/1/config',
json: true,
body: { params: { companies: ['US', 'DK', 'SE'] } },
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
},
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.params.companies).toEqual(['US', 'DK', 'SE']);
done();
}).catch((error) => { console.log(error); });
});
});
it('fail to update if master key is missing', (done) => {
request.post({
url: 'http://localhost:8378/1/config',
json: true,
body: { params: { companies: [] } },
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
},
}, (error, response, body) => {
expect(response.statusCode).toEqual(401);
expect(body.error).toEqual('unauthorized');
done();
});
});
});

View File

@@ -192,7 +192,7 @@ function mockFacebook() {
function clearData() {
var promises = [];
for (var conn in DatabaseAdapter.dbConnections) {
promises.push(DatabaseAdapter.dbConnections[conn].deleteEverything());
// promises.push(DatabaseAdapter.dbConnections[conn].deleteEverything());
}
return Promise.all(promises);
}