2018-03-26 20:50:43 +00:00
|
|
|
/* global describe, it */
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
'use strict';
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var reducer = require('../src/helpers/reducer');
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
require('should');
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
describe('Reducer', function() {
|
|
|
|
it('should convert array object pair to key-value object', function(done) {
|
2018-03-26 20:50:43 +00:00
|
|
|
var query = [
|
2018-06-25 17:42:50 +00:00
|
|
|
{ name: 'key', value: 'value' },
|
|
|
|
{ name: 'foo', value: 'bar' }
|
|
|
|
];
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var obj = query.reduce(reducer, {});
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
obj.should.be.an.Object;
|
|
|
|
obj.should.eql({ key: 'value', foo: 'bar' });
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
done();
|
|
|
|
});
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
it('should convert multi-dimensional arrays to key=[array] object', function(done) {
|
2018-03-26 20:50:43 +00:00
|
|
|
var query = [
|
2018-06-25 17:42:50 +00:00
|
|
|
{ name: 'key', value: 'value' },
|
|
|
|
{ name: 'foo', value: 'bar1' },
|
|
|
|
{ name: 'foo', value: 'bar2' }
|
|
|
|
];
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var obj = query.reduce(reducer, {});
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
obj.should.be.an.Object;
|
|
|
|
obj.should.eql({ key: 'value', foo: ['bar1', 'bar2'] });
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|