2023-02-03 00:09:45 +01:00
|
|
|
const parser = require("../src/index");
|
|
|
|
|
|
|
|
describe("parser", () => {
|
2023-02-03 16:38:40 +01:00
|
|
|
it("should parse the bru file", () => {
|
2023-02-03 03:31:44 +01:00
|
|
|
const input = `
|
2023-02-04 01:36:02 +01:00
|
|
|
query {
|
|
|
|
apiKey: secret
|
|
|
|
numbers: 998877665
|
|
|
|
}
|
|
|
|
|
|
|
|
query:disabled {
|
|
|
|
message: hello
|
|
|
|
}
|
|
|
|
|
2023-02-03 03:31:44 +01:00
|
|
|
headers {
|
2023-02-03 18:57:06 +01:00
|
|
|
content-type: application/json
|
|
|
|
Authorization: Bearer 123
|
|
|
|
}
|
|
|
|
|
|
|
|
headers:disabled {
|
|
|
|
transaction-id: {{transactionId}}
|
2023-02-03 16:38:40 +01:00
|
|
|
}
|
2023-02-03 03:31:44 +01:00
|
|
|
|
2023-02-04 01:36:02 +01:00
|
|
|
body:form-urlencoded {
|
|
|
|
apikey: secret
|
|
|
|
numbers: +91998877665
|
|
|
|
}
|
|
|
|
|
|
|
|
body:form-urlencoded:disabled {
|
|
|
|
message: hello
|
|
|
|
}
|
|
|
|
|
|
|
|
body:multipart-form {
|
|
|
|
apikey: secret
|
|
|
|
numbers: +91998877665
|
|
|
|
}
|
|
|
|
|
|
|
|
body:multipart-form:disabled {
|
|
|
|
message: hello
|
|
|
|
}
|
|
|
|
|
|
|
|
body:json {
|
|
|
|
{
|
|
|
|
"hello": "world"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
body:text {
|
|
|
|
This is a text body
|
|
|
|
}
|
|
|
|
|
|
|
|
body:xml {
|
|
|
|
<xml>
|
|
|
|
<name>John</name>
|
|
|
|
<age>30</age>
|
|
|
|
</xml>
|
|
|
|
}
|
|
|
|
|
|
|
|
body:graphql {
|
|
|
|
{
|
|
|
|
launchesPast {
|
|
|
|
launch_site {
|
|
|
|
site_name
|
|
|
|
}
|
|
|
|
launch_success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
body:graphql:vars {
|
|
|
|
{
|
|
|
|
"limit": 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 03:31:44 +01:00
|
|
|
script {
|
|
|
|
function onResponse(request, response) {
|
|
|
|
expect(response.status).to.equal(200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2023-02-03 00:09:45 +01:00
|
|
|
|
2023-02-03 03:31:44 +01:00
|
|
|
const output = parser(input);
|
2023-02-03 16:38:40 +01:00
|
|
|
const expected = {
|
2023-02-04 01:36:02 +01:00
|
|
|
"query": [{
|
|
|
|
"name": "apiKey",
|
|
|
|
"value": "secret",
|
|
|
|
"enabled": true
|
|
|
|
}, {
|
|
|
|
"name": "numbers",
|
|
|
|
"value": "998877665",
|
|
|
|
"enabled": true
|
|
|
|
}, {
|
|
|
|
"name": "message",
|
|
|
|
"value": "hello",
|
|
|
|
"enabled": false
|
|
|
|
}],
|
2023-02-03 16:38:40 +01:00
|
|
|
"headers": [
|
|
|
|
{
|
2023-02-03 18:57:06 +01:00
|
|
|
"name": "content-type",
|
|
|
|
"value": "application/json",
|
2023-02-03 16:38:40 +01:00
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
{
|
2023-02-03 18:57:06 +01:00
|
|
|
"name": "Authorization",
|
|
|
|
"value": "Bearer 123",
|
2023-02-03 16:38:40 +01:00
|
|
|
"enabled": true
|
2023-02-03 18:57:06 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "transaction-id",
|
|
|
|
"value": "{{transactionId}}",
|
|
|
|
"enabled": false
|
2023-02-03 16:38:40 +01:00
|
|
|
}
|
|
|
|
],
|
2023-02-04 01:36:02 +01:00
|
|
|
"body": {
|
|
|
|
"json": " {\n \"hello\": \"world\"\n }",
|
|
|
|
"text": " This is a text body",
|
|
|
|
"xml": " <xml>\n <name>John</name>\n <age>30</age>\n </xml>",
|
|
|
|
"graphql": {
|
|
|
|
"query": " {\n launchesPast {\n launch_site {\n site_name\n }\n launch_success\n }\n }",
|
|
|
|
"variables": " {\n \"limit\": 5\n }"
|
|
|
|
},
|
|
|
|
"formUrlEncoded": [
|
|
|
|
{
|
|
|
|
"name": "apikey",
|
|
|
|
"value": "secret",
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "numbers",
|
|
|
|
"value": "+91998877665",
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "message",
|
|
|
|
"value": "hello",
|
|
|
|
"enabled": false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"multipartForm": [
|
|
|
|
{
|
|
|
|
"name": "apikey",
|
|
|
|
"value": "secret",
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "numbers",
|
|
|
|
"value": "+91998877665",
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "message",
|
|
|
|
"value": "hello",
|
|
|
|
"enabled": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2023-02-03 16:38:40 +01:00
|
|
|
"script": " function onResponse(request, response) {\n expect(response.status).to.equal(200);\n }"
|
|
|
|
}
|
2023-02-03 18:57:06 +01:00
|
|
|
|
2023-02-04 01:36:02 +01:00
|
|
|
// console.log(JSON.stringify(output, null, 2));
|
2023-02-03 16:38:40 +01:00
|
|
|
expect(output).toEqual(expected);
|
2023-02-03 00:09:45 +01:00
|
|
|
});
|
|
|
|
});
|