insomnia/packages/insomnia-httpsnippet/test/reducer.js
2018-12-12 12:36:11 -05:00

36 lines
830 B
JavaScript
Executable File

/* global describe, it */
'use strict';
var reducer = require('../src/helpers/reducer');
require('should');
describe('Reducer', function() {
it('should convert array object pair to key-value object', function(done) {
var query = [{ name: 'key', value: 'value' }, { name: 'foo', value: 'bar' }];
var obj = query.reduce(reducer, {});
obj.should.be.an.Object;
obj.should.eql({ key: 'value', foo: 'bar' });
done();
});
it('should convert multi-dimensional arrays to key=[array] object', function(done) {
var query = [
{ name: 'key', value: 'value' },
{ name: 'foo', value: 'bar1' },
{ name: 'foo', value: 'bar2' },
];
var obj = query.reduce(reducer, {});
obj.should.be.an.Object;
obj.should.eql({ key: 'value', foo: ['bar1', 'bar2'] });
done();
});
});