processNested.spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. const assert = require('assert');
  3. const processNested = require('../lib').processNested;
  4. describe('Test Convert Flatten object to Nested object', function() {
  5. it('With no nested data', function(){
  6. const data = {
  7. 'firstname': 'John',
  8. 'lastname': 'Doe',
  9. 'age': 22
  10. },
  11. excerpt= { firstname: 'John', lastname: 'Doe', age: 22 },
  12. processed = processNested(data);
  13. assert.deepEqual(processed, excerpt);
  14. });
  15. it('With nested data', function(){
  16. const data = {
  17. 'firstname': 'John',
  18. 'lastname': 'Doe',
  19. 'age': 22,
  20. 'hobbies[0]': 'Cinema',
  21. 'hobbies[1]': 'Bike',
  22. 'address[line]': '78 Lynch Street',
  23. 'address[city]': 'Milwaukee',
  24. 'friends[0][name]': 'Jane',
  25. 'friends[0][lastname]': 'Doe',
  26. 'friends[1][name]': 'Joe',
  27. 'friends[1][lastname]': 'Doe'
  28. },
  29. excerpt = {
  30. firstname: 'John',
  31. lastname: 'Doe',
  32. age: 22,
  33. hobbies: [ 'Cinema', 'Bike' ],
  34. address: { line: '78 Lynch Street', city: 'Milwaukee' },
  35. friends: [
  36. { name: 'Jane', lastname: 'Doe' },
  37. { name: 'Joe', lastname: 'Doe' }
  38. ]
  39. },
  40. processed = processNested(data);
  41. assert.deepEqual(processed, excerpt);
  42. });
  43. });