insomnia/packages/insomnia-httpsnippet/test/reducer.js

36 lines
830 B
JavaScript
Raw Normal View History

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