From 6fe050b397dc310c955a2fdffe0313047e06db01 Mon Sep 17 00:00:00 2001 From: Peter Theill Date: Sun, 7 Feb 2016 01:20:15 +0100 Subject: [PATCH] Add read/write test for _GlobalConfig --- spec/ParseGlobalConfig.spec.js | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 spec/ParseGlobalConfig.spec.js diff --git a/spec/ParseGlobalConfig.spec.js b/spec/ParseGlobalConfig.spec.js new file mode 100644 index 00000000..dd04a997 --- /dev/null +++ b/spec/ParseGlobalConfig.spec.js @@ -0,0 +1,49 @@ +// run test when changing related file using +// $ TESTING=1 node_modules/jasmine/bin/jasmine.js spec/ParseGlobalConfig.spec.js + +var auth = require('../Auth'); +var cache = require('../cache'); +var Config = require('../Config'); +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' } }, {}); + }); + + 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'); + 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'); + done(); + }).catch((error) => { console.log(error); }); + }); + + +});