object.util.Test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var objectUtil = require('../../../src/server/util/object.util');
  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. },
  35. 'from',
  36. 'to',
  37. 'timestamp',
  38. 'expire',
  39. 'location');
  40. assert.strictEqual(false, testing.pass);
  41. assert.strictEqual(true, testing.message.indexOf('timestamp') > -1);
  42. assert.strictEqual(true, testing.message.indexOf('expire') > -1);
  43. assert.strictEqual(true, testing.message.indexOf('location') > -1);
  44. });
  45. });
  46. describe('When test timestampToLong', function () {
  47. it('should return 200.', function () {
  48. var now = new Date(1479028394000);
  49. var val = objectUtil.timestampToLong(now);
  50. assert.strictEqual(1479028394000, val);
  51. });
  52. });
  53. });