-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#1296): toml tests: simple header
- Loading branch information
1 parent
48ec87e
commit 2aa073c
Showing
7 changed files
with
103 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
const stringify = require('../lib/stringify'); | ||
const { get, each } = require('lodash'); | ||
|
||
const jsonToToml = (json) => { | ||
return stringify(json); | ||
const formattedJson = { | ||
meta: { | ||
name: get(json, 'meta.name'), | ||
type: get(json, 'meta.type'), | ||
seq: get(json, 'meta.seq') | ||
}, | ||
http: { | ||
method: get(json, 'http.method'), | ||
url: get(json, 'http.url', '') | ||
} | ||
}; | ||
|
||
if (json.headers && json.headers.length) { | ||
formattedJson.headers = {}; | ||
each(json.headers, (header) => { | ||
formattedJson.headers[header.name] = header.value; | ||
}); | ||
} | ||
|
||
return stringify(formattedJson); | ||
}; | ||
|
||
module.exports = jsonToToml; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Toml = require('@iarna/toml'); | ||
|
||
const tomlToJson = (toml) => { | ||
const json = Toml.parse(toml); | ||
|
||
const formattedJson = { | ||
meta: { | ||
name: json.meta.name, | ||
type: json.meta.type, | ||
seq: json.meta.seq | ||
}, | ||
http: { | ||
method: json.http.method, | ||
url: json.http.url | ||
} | ||
}; | ||
|
||
if (json.headers) { | ||
formattedJson.headers = []; | ||
Object.keys(json.headers).forEach((key) => { | ||
formattedJson.headers.push({ | ||
name: key, | ||
value: json.headers[key], | ||
enabled: true | ||
}); | ||
}); | ||
} | ||
|
||
return formattedJson; | ||
}; | ||
|
||
module.exports = tomlToJson; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
Cookie = 'foo=bar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const jsonToToml = require('../src/jsonToToml'); | ||
const { describe } = require('@jest/globals'); | ||
const tomlToJson = require('../src/tomlToJson'); | ||
|
||
const fixtures = ['methods/get', 'methods/delete']; | ||
const fixtures = ['methods/get', 'methods/delete', 'headers/simple']; | ||
|
||
describe('bruno toml', () => { | ||
fixtures.forEach((fixture) => { | ||
describe(fixture, () => { | ||
const json = require(`./${fixture}/request.json`); | ||
const toml = fs.readFileSync(path.join(__dirname, fixture, 'request.toml'), 'utf8'); | ||
|
||
if (process.env.DEBUG === 'true') { | ||
console.log(`DEBUG: Running ${fixture} tests`); | ||
console.log('json', JSON.stringify(json, null, 2)); | ||
console.log('toml', toml); | ||
console.log('jsonToToml', jsonToToml(json)); | ||
console.log('tomlToJson', JSON.stringify(tomlToJson(toml), null, 2)); | ||
} | ||
|
||
it(`should convert json to toml`, () => { | ||
expect(toml).toEqual(jsonToToml(json)); | ||
}); | ||
|
||
it(`should convert toml to json`, () => { | ||
expect(json).toEqual(tomlToJson(toml)); | ||
}); | ||
}); | ||
}); | ||
}); |
35 changes: 0 additions & 35 deletions
35
packages/bruno-toml/tests/jsonToToml/headers/headers-simple.spec.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.