Migrate ParseGlobalConfig.spec to new database storage API.
This commit is contained in:
@@ -5,21 +5,21 @@ var Parse = require('parse/node').Parse;
|
|||||||
let Config = require('../src/Config');
|
let Config = require('../src/Config');
|
||||||
|
|
||||||
describe('a GlobalConfig', () => {
|
describe('a GlobalConfig', () => {
|
||||||
beforeEach(function(done) {
|
beforeEach(function (done) {
|
||||||
let config = new Config('test');
|
let config = new Config('test');
|
||||||
config.database.rawCollection('_GlobalConfig')
|
config.database.adaptiveCollection('_GlobalConfig')
|
||||||
.then(coll => coll.updateOne({ '_id': 1}, { $set: { params: { companies: ['US', 'DK'] } } }, { upsert: true }))
|
.then(coll => coll.upsertOne({ '_id': 1 }, { $set: { params: { companies: ['US', 'DK'] } } }))
|
||||||
.then(done());
|
.then(done());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be retrieved', (done) => {
|
it('can be retrieved', (done) => {
|
||||||
request.get({
|
request.get({
|
||||||
url: 'http://localhost:8378/1/config',
|
url : 'http://localhost:8378/1/config',
|
||||||
json: true,
|
json : true,
|
||||||
headers: {
|
headers: {
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-Master-Key': 'test',
|
'X-Parse-Master-Key' : 'test'
|
||||||
},
|
}
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
expect(response.statusCode).toEqual(200);
|
expect(response.statusCode).toEqual(200);
|
||||||
expect(body.params.companies).toEqual(['US', 'DK']);
|
expect(body.params.companies).toEqual(['US', 'DK']);
|
||||||
@@ -29,13 +29,13 @@ describe('a GlobalConfig', () => {
|
|||||||
|
|
||||||
it('can be updated when a master key exists', (done) => {
|
it('can be updated when a master key exists', (done) => {
|
||||||
request.put({
|
request.put({
|
||||||
url: 'http://localhost:8378/1/config',
|
url : 'http://localhost:8378/1/config',
|
||||||
json: true,
|
json : true,
|
||||||
body: { params: { companies: ['US', 'DK', 'SE'] } },
|
body : { params: { companies: ['US', 'DK', 'SE'] } },
|
||||||
headers: {
|
headers: {
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-Master-Key': 'test'
|
'X-Parse-Master-Key' : 'test'
|
||||||
},
|
}
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
expect(response.statusCode).toEqual(200);
|
expect(response.statusCode).toEqual(200);
|
||||||
expect(body.result).toEqual(true);
|
expect(body.result).toEqual(true);
|
||||||
@@ -45,35 +45,35 @@ describe('a GlobalConfig', () => {
|
|||||||
|
|
||||||
it('fail to update if master key is missing', (done) => {
|
it('fail to update if master key is missing', (done) => {
|
||||||
request.put({
|
request.put({
|
||||||
url: 'http://localhost:8378/1/config',
|
url : 'http://localhost:8378/1/config',
|
||||||
json: true,
|
json : true,
|
||||||
body: { params: { companies: [] } },
|
body : { params: { companies: [] } },
|
||||||
headers: {
|
headers: {
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-REST-API-Key': 'rest'
|
'X-Parse-REST-API-Key' : 'rest'
|
||||||
},
|
}
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
expect(response.statusCode).toEqual(403);
|
expect(response.statusCode).toEqual(403);
|
||||||
expect(body.error).toEqual('unauthorized: master key is required');
|
expect(body.error).toEqual('unauthorized: master key is required');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('failed getting config when it is missing', (done) => {
|
it('failed getting config when it is missing', (done) => {
|
||||||
let config = new Config('test');
|
let config = new Config('test');
|
||||||
config.database.rawCollection('_GlobalConfig')
|
config.database.adaptiveCollection('_GlobalConfig')
|
||||||
.then(coll => coll.deleteOne({ '_id': 1}, {}, {}))
|
.then(coll => coll.deleteOne({ '_id': 1 }))
|
||||||
.then(_ => {
|
.then(() => {
|
||||||
request.get({
|
request.get({
|
||||||
url: 'http://localhost:8378/1/config',
|
url : 'http://localhost:8378/1/config',
|
||||||
json: true,
|
json : true,
|
||||||
headers: {
|
headers: {
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-Master-Key': 'test',
|
'X-Parse-Master-Key' : 'test'
|
||||||
},
|
}
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
expect(response.statusCode).toEqual(404);
|
expect(response.statusCode).toEqual(200);
|
||||||
expect(body.code).toEqual(Parse.Error.INVALID_KEY_NAME);
|
expect(body.params).toEqual({});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ export default class MongoCollection {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteOne(query) {
|
||||||
|
return this._mongoCollection.deleteOne(query);
|
||||||
|
}
|
||||||
|
|
||||||
remove(query) {
|
remove(query) {
|
||||||
return this._mongoCollection.remove(query);
|
return this._mongoCollection.remove(query);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user