mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-22 14:41:04 +01:00
feat(#1296): toml tests: different kinds of headers
This commit is contained in:
parent
2aa073c69a
commit
1754ea9f59
@ -17,8 +17,6 @@
|
||||
* You can search for "modified for bruno-toml" to see the changes
|
||||
*/
|
||||
|
||||
|
||||
|
||||
'use strict'
|
||||
module.exports = stringify
|
||||
module.exports.value = stringifyInline
|
||||
@ -73,7 +71,14 @@ function stringifyObject (prefix, indent, obj) {
|
||||
}
|
||||
})
|
||||
if (result.length > 0) result.push('')
|
||||
const complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
|
||||
|
||||
// original
|
||||
// const complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
|
||||
|
||||
// modified for bruno-toml
|
||||
// we don't want to indent tables
|
||||
const complexIndent = '';
|
||||
|
||||
complexKeys.forEach(key => {
|
||||
result.push(stringifyComplex(prefix, complexIndent, key, obj[key]))
|
||||
})
|
||||
@ -292,7 +297,12 @@ function stringifyComplexTable (prefix, indent, key, value) {
|
||||
const fullKey = prefix + stringifyKey(key)
|
||||
let result = ''
|
||||
if (getInlineKeys(value).length > 0) {
|
||||
result += indent + '[' + fullKey + ']\n'
|
||||
// original
|
||||
// result += indent + '[' + fullKey + ']\n'
|
||||
|
||||
// modified for bruno-toml
|
||||
// we don't want to indent tables
|
||||
result += '[' + fullKey + ']\n'
|
||||
}
|
||||
return result + stringifyObject(fullKey + '.', indent, value)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
const stringify = require('../lib/stringify');
|
||||
const { get, each } = require('lodash');
|
||||
const { get, each, filter } = require('lodash');
|
||||
|
||||
const jsonToToml = (json) => {
|
||||
const formattedJson = {
|
||||
@ -15,10 +15,17 @@ const jsonToToml = (json) => {
|
||||
};
|
||||
|
||||
if (json.headers && json.headers.length) {
|
||||
formattedJson.headers = {};
|
||||
each(json.headers, (header) => {
|
||||
const enabledHeaders = filter(json.headers, (header) => header.enabled);
|
||||
const disabledHeaders = filter(json.headers, (header) => !header.enabled);
|
||||
each(enabledHeaders, (header) => {
|
||||
formattedJson.headers = formattedJson.headers || {};
|
||||
formattedJson.headers[header.name] = header.value;
|
||||
});
|
||||
each(disabledHeaders, (header) => {
|
||||
formattedJson.headers = formattedJson.headers || {};
|
||||
formattedJson.headers.disabled = formattedJson.headers.disabled || {};
|
||||
formattedJson.headers.disabled[header.name] = header.value;
|
||||
});
|
||||
}
|
||||
|
||||
return stringify(formattedJson);
|
||||
|
@ -18,6 +18,17 @@ const tomlToJson = (toml) => {
|
||||
if (json.headers) {
|
||||
formattedJson.headers = [];
|
||||
Object.keys(json.headers).forEach((key) => {
|
||||
if (key === 'disabled') {
|
||||
Object.keys(json.headers['disabled']).forEach((disabledKey) => {
|
||||
formattedJson.headers.push({
|
||||
name: disabledKey,
|
||||
value: json.headers[key][disabledKey],
|
||||
enabled: false
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
formattedJson.headers.push({
|
||||
name: key,
|
||||
value: json.headers[key],
|
||||
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Get users",
|
||||
"type": "http",
|
||||
"seq": 1
|
||||
},
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"url": "https://reqres.in/api/users"
|
||||
},
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "Cookie",
|
||||
"value": "foo=bar",
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[meta]
|
||||
name = 'Get users'
|
||||
type = 'http'
|
||||
seq = 1
|
||||
|
||||
[http]
|
||||
method = 'GET'
|
||||
url = 'https://reqres.in/api/users'
|
||||
|
||||
[headers]
|
||||
Content-Type = 'application/json'
|
||||
|
||||
[headers.disabled]
|
||||
Cookie = 'foo=bar'
|
23
packages/bruno-toml/tests/headers/empty-header/request.json
Normal file
23
packages/bruno-toml/tests/headers/empty-header/request.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Get users",
|
||||
"type": "http",
|
||||
"seq": 1
|
||||
},
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"url": "https://reqres.in/api/users"
|
||||
},
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "Empty-Header",
|
||||
"value": "",
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
12
packages/bruno-toml/tests/headers/empty-header/request.toml
Normal file
12
packages/bruno-toml/tests/headers/empty-header/request.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[meta]
|
||||
name = 'Get users'
|
||||
type = 'http'
|
||||
seq = 1
|
||||
|
||||
[http]
|
||||
method = 'GET'
|
||||
url = 'https://reqres.in/api/users'
|
||||
|
||||
[headers]
|
||||
Content-Type = 'application/json'
|
||||
Empty-Header = ''
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Get users",
|
||||
"type": "http",
|
||||
"seq": 1
|
||||
},
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"url": "https://reqres.in/api/users"
|
||||
},
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "Spaces In Header",
|
||||
"value": "",
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
[meta]
|
||||
name = 'Get users'
|
||||
type = 'http'
|
||||
seq = 1
|
||||
|
||||
[http]
|
||||
method = 'GET'
|
||||
url = 'https://reqres.in/api/users'
|
||||
|
||||
[headers]
|
||||
Content-Type = 'application/json'
|
||||
'Spaces In Header' = ''
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Get users",
|
||||
"type": "http",
|
||||
"seq": 1
|
||||
},
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"url": "https://reqres.in/api/users"
|
||||
},
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "🐶",
|
||||
"value": "🚀",
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
[meta]
|
||||
name = 'Get users'
|
||||
type = 'http'
|
||||
seq = 1
|
||||
|
||||
[http]
|
||||
method = 'GET'
|
||||
url = 'https://reqres.in/api/users'
|
||||
|
||||
[headers]
|
||||
Content-Type = 'application/json'
|
||||
'🐶' = '🚀'
|
@ -3,7 +3,15 @@ const path = require('path');
|
||||
const jsonToToml = require('../src/jsonToToml');
|
||||
const tomlToJson = require('../src/tomlToJson');
|
||||
|
||||
const fixtures = ['methods/get', 'methods/delete', 'headers/simple'];
|
||||
const fixtures = [
|
||||
'methods/get',
|
||||
'methods/delete',
|
||||
'headers/simple',
|
||||
'headers/empty-header',
|
||||
'headers/spaces-in-header',
|
||||
'headers/unicode-in-header',
|
||||
'headers/disabled-header'
|
||||
];
|
||||
|
||||
describe('bruno toml', () => {
|
||||
fixtures.forEach((fixture) => {
|
||||
|
Loading…
Reference in New Issue
Block a user