objectUtil.Test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. var objectUtil = require('../../../src/doctor/util/objectUtil');
  3. var assert = require('assert');
  4. describe('Object utilities', function () {
  5. describe('When test isJsonObject with "Array" object', function () {
  6. it('should return false', function () {
  7. assert.strictEqual(objectUtil.isJsonObject([]), false);
  8. })
  9. });
  10. describe('When test isJsonObject with "Dict" object', function () {
  11. it('should return true', function () {
  12. assert.strictEqual(objectUtil.isJsonObject({age: 2}), true);
  13. })
  14. });
  15. describe('When test fieldsCheck with full fields', function () {
  16. it('should return false and missing fields.', function () {
  17. var testing = objectUtil.fieldsCheck({
  18. from: 'Sand',
  19. to: 'Rose',
  20. data: 'Hello world.'
  21. },
  22. 'from',
  23. 'to',
  24. 'data');
  25. assert.strictEqual(true, testing.pass);
  26. });
  27. });
  28. describe('When test fieldsCheck with missing fields', function () {
  29. it('should return false and missing fields.', function () {
  30. var testing = objectUtil.fieldsCheck({
  31. from: 'Sand',
  32. to: 'Rose',
  33. content: 'Hello world.'},
  34. 'from',
  35. 'to',
  36. 'timestamp',
  37. 'expire',
  38. 'location');
  39. assert.strictEqual(false, testing.pass);
  40. assert.strictEqual(true, testing.message.indexOf('timestamp') > -1);
  41. assert.strictEqual(true, testing.message.indexOf('expire') > -1);
  42. assert.strictEqual(true, testing.message.indexOf('location') > -1);
  43. });
  44. });
  45. });