db_test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. describe('App.db', function () {
  20. describe('#App.db.set', function () {
  21. afterEach(function () {
  22. App.db.cleanUp();
  23. });
  24. it('should create one object', function () {
  25. App.db.set('a', 'b', 1);
  26. expect(App.db.data.a.b).to.equal(1);
  27. });
  28. it('should create nested objects', function () {
  29. App.db.set('b.c', 'd', 1);
  30. expect(App.db.data.b.c.d).to.equal(1);
  31. });
  32. });
  33. describe('#App.db.get', function () {
  34. after(function () {
  35. App.db.cleanUp();
  36. });
  37. it('should return undefined', function () {
  38. var ret = App.db.get('a', 'b');
  39. expect(ret).to.be.undefined;
  40. });
  41. it('should return set value', function () {
  42. App.db.set('a', 'b', 10);
  43. var ret = App.db.get('a', 'b');
  44. expect(ret).to.equal(10);
  45. });
  46. });
  47. describe('#App.db.setProperties', function () {
  48. afterEach(function () {
  49. App.db.cleanUp();
  50. });
  51. it('should create one object', function () {
  52. App.db.setProperties('a', {b: 1, c: 2});
  53. expect(App.db.data.a).to.eql({b: 1, c: 2});
  54. });
  55. it('should create nested objects', function () {
  56. App.db.setProperties('b.c', {b: 1, c: 2});
  57. expect(App.db.data.b.c).to.eql({b: 1, c: 2});
  58. });
  59. });
  60. describe('#App.db.getProperties', function () {
  61. after(function () {
  62. App.db.cleanUp();
  63. });
  64. it('should return undefined', function () {
  65. var ret = App.db.getProperties('a', ['b', 'c']);
  66. expect(ret).to.eql({b: undefined, c: undefined});
  67. });
  68. it('should return set value', function () {
  69. App.db.setProperties('a', {b: 1, c: 2});
  70. var ret = App.db.getProperties('a', ['b', 'c']);
  71. expect(ret).to.eql({b: 1, c: 2});
  72. });
  73. });
  74. });