data_manipulation_test.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 data_manipulation = require('utils/data_manipulation');
  19. describe('data_manipulation', function () {
  20. describe('#rejectPropertyValues', function () {
  21. it('Basic test', function () {
  22. var collection = [
  23. {n: 'v1'},
  24. {n: 'v2'},
  25. {n: 'v3'},
  26. {n: 'v4'}
  27. ],
  28. key = 'n',
  29. valuesToReject = ['v2', 'v3'];
  30. var result = data_manipulation.rejectPropertyValues(collection, key, valuesToReject);
  31. expect(result).to.eql([
  32. {n: 'v1'},
  33. {n: 'v4'}
  34. ]);
  35. });
  36. });
  37. describe('#filterPropertyValues', function () {
  38. it('Basic test', function () {
  39. var collection = [
  40. {n: 'v1'},
  41. {n: 'v2'},
  42. {n: 'v3'},
  43. {n: 'v4'}
  44. ],
  45. key = 'n',
  46. valuesToFilter = ['v2', 'v3'];
  47. var result = data_manipulation.filterPropertyValues(collection, key, valuesToFilter);
  48. expect(result).to.eql([
  49. {n: 'v2'},
  50. {n: 'v3'}
  51. ]);
  52. });
  53. });
  54. describe('#groupPropertyValues', function () {
  55. it('Basic test', function () {
  56. var collection = [
  57. {n: 'v1'},
  58. {n: 'v2'},
  59. {n: 'v2'},
  60. {n: 'v4'}
  61. ],
  62. key = 'n';
  63. var result = data_manipulation.groupPropertyValues(collection, key);
  64. expect(result).to.eql({
  65. v1: [
  66. {n: 'v1'}
  67. ],
  68. v2: [
  69. {n: 'v2'},
  70. {n: 'v2'}
  71. ],
  72. v4: [
  73. {n: 'v4'}
  74. ]});
  75. });
  76. });
  77. });