2023-01-14 15:46:09 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2023-09-21 21:12:48 +02:00
|
|
|
const { bruToJson } = require('../src');
|
2023-01-14 15:46:09 +01:00
|
|
|
|
|
|
|
describe('bruToJson', () => {
|
2023-01-16 19:50:22 +01:00
|
|
|
it('should parse .bru file contents', () => {
|
|
|
|
const requestFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'request.bru'), 'utf8');
|
|
|
|
const result = bruToJson(requestFile);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
2023-09-21 21:12:48 +02:00
|
|
|
type: 'http-request',
|
|
|
|
name: 'Send Bulk SMS',
|
|
|
|
seq: 1,
|
|
|
|
request: {
|
|
|
|
method: 'GET',
|
|
|
|
url: 'https://api.textlocal.in/bulk_json?apiKey=secret=&numbers=919988776655&message=hello&sender=600010',
|
|
|
|
params: [
|
2023-01-15 18:12:56 +01:00
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'apiKey',
|
|
|
|
value: 'secret'
|
2023-01-15 18:12:56 +01:00
|
|
|
},
|
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'numbers',
|
|
|
|
value: '998877665'
|
2023-01-16 19:50:22 +01:00
|
|
|
},
|
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'message',
|
|
|
|
value: 'hello'
|
2023-01-15 18:12:56 +01:00
|
|
|
}
|
2023-01-15 18:32:59 +01:00
|
|
|
],
|
2023-09-21 21:12:48 +02:00
|
|
|
headers: [
|
2023-01-16 19:50:22 +01:00
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'content-type',
|
|
|
|
value: 'application/json'
|
2023-01-16 19:50:22 +01:00
|
|
|
},
|
2023-01-15 18:32:59 +01:00
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'accept-language',
|
|
|
|
value: 'en-US,en;q=0.9,hi;q=0.8'
|
2023-01-15 18:32:59 +01:00
|
|
|
},
|
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: false,
|
|
|
|
name: 'transaction-id',
|
|
|
|
value: '{{transactionId}}'
|
2023-01-15 18:32:59 +01:00
|
|
|
}
|
2023-01-16 19:50:22 +01:00
|
|
|
],
|
2023-09-21 21:12:48 +02:00
|
|
|
body: {
|
|
|
|
mode: 'json',
|
|
|
|
json: '{\n "apikey": "secret",\n "numbers": "+91998877665"\n}',
|
|
|
|
graphql: {
|
|
|
|
query: '{\n launchesPast {\n launch_success\n }\n}'
|
2023-01-16 19:50:22 +01:00
|
|
|
},
|
2023-09-21 21:12:48 +02:00
|
|
|
text: 'Hello, there. You must be from the past',
|
|
|
|
xml: '<body>back to the ice age</body>',
|
|
|
|
formUrlEncoded: [
|
2023-01-16 19:50:22 +01:00
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'username',
|
|
|
|
value: 'john'
|
2023-01-16 19:50:22 +01:00
|
|
|
},
|
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: false,
|
|
|
|
name: 'password',
|
|
|
|
value: '{{password}}'
|
2023-01-16 19:50:22 +01:00
|
|
|
}
|
|
|
|
],
|
2023-09-21 21:12:48 +02:00
|
|
|
multipartForm: [
|
2023-01-16 19:50:22 +01:00
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: true,
|
|
|
|
name: 'username',
|
|
|
|
value: 'nash'
|
2023-01-16 19:50:22 +01:00
|
|
|
},
|
|
|
|
{
|
2023-09-21 21:12:48 +02:00
|
|
|
enabled: false,
|
|
|
|
name: 'password',
|
|
|
|
value: 'governingdynamics'
|
2023-01-16 19:50:22 +01:00
|
|
|
}
|
|
|
|
]
|
2023-01-22 19:09:16 +01:00
|
|
|
},
|
2023-09-21 21:12:48 +02:00
|
|
|
script: "const foo='bar';",
|
|
|
|
tests: "bruno.test('200 ok', () => {});"
|
2023-01-14 23:21:48 +01:00
|
|
|
}
|
2023-01-16 19:50:22 +01:00
|
|
|
});
|
2023-01-14 15:46:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-21 20:05:58 +01:00
|
|
|
describe('jsonToBru - should parse bru file having empty url', () => {
|
|
|
|
const requestFile = `name Send Bulk SMS
|
|
|
|
method GET
|
|
|
|
url
|
|
|
|
type http-request
|
|
|
|
body-mode none
|
|
|
|
seq 1
|
|
|
|
`;
|
2023-01-14 15:46:09 +01:00
|
|
|
|
2023-01-21 20:05:58 +01:00
|
|
|
it('should parse .bru file having empty url', () => {
|
|
|
|
const result = bruToJson(requestFile);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
type: 'http-request',
|
|
|
|
name: 'Send Bulk SMS',
|
|
|
|
seq: 1,
|
|
|
|
request: {
|
|
|
|
method: 'GET',
|
|
|
|
url: '',
|
|
|
|
params: [],
|
|
|
|
headers: [],
|
2023-01-22 19:09:16 +01:00
|
|
|
body: { mode: 'none' },
|
2023-09-21 21:12:48 +02:00
|
|
|
script: '',
|
|
|
|
tests: ''
|
2023-01-21 20:05:58 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|