2020-07-07 18:58:46 +00:00
|
|
|
import createHeaders from 'consul-ui/utils/http/create-headers';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module('Unit | Utility | http/create-headers', function () {
|
2020-07-07 18:58:46 +00:00
|
|
|
const parseHeaders = createHeaders();
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it converts lines of header-like strings into an object', function (assert) {
|
2020-07-07 18:58:46 +00:00
|
|
|
const expected = {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'X-Consul-Index': '1',
|
|
|
|
};
|
|
|
|
const lines = `
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Consul-Index: 1
|
|
|
|
`.split('\n');
|
|
|
|
const actual = parseHeaders(lines);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it parses header values with colons correctly', function (assert) {
|
2020-07-13 13:22:15 +00:00
|
|
|
const expected = {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'X-Consul-Index': '1:2:3',
|
|
|
|
};
|
|
|
|
const lines = `
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Consul-Index: 1:2:3
|
|
|
|
`.split('\n');
|
|
|
|
const actual = parseHeaders(lines);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
2020-07-07 18:58:46 +00:00
|
|
|
});
|