mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 20:25:38 +00:00
* fix: Support @contentType for multiline values Fixes the issue where the @contentType annotation broke the parsing of multiline values. * chore: add dotall flag to fileExtractContentType Not strictly needed since body:file uses single-line values in practice, but doesn't hurt and matches what multipartExtractContentType does. --------- Co-authored-by: Márk Dániel Seres <markdaniel.seres@tesco.com>
208 lines
3.6 KiB
JavaScript
208 lines
3.6 KiB
JavaScript
const parser = require('../src/bruToJson');
|
|
|
|
describe('bruToJson parser', () => {
|
|
describe('body:ws', () => {
|
|
it('infers message and settings | smoke', () => {
|
|
const input = `
|
|
body:ws {
|
|
type: json
|
|
name: message 1
|
|
content: '''
|
|
{"foo":"bar"}
|
|
'''
|
|
}
|
|
|
|
settings {
|
|
timeout: 30
|
|
}
|
|
`;
|
|
|
|
const expected = {
|
|
body: {
|
|
mode: 'ws',
|
|
ws: [
|
|
{
|
|
content: '{"foo":"bar"}',
|
|
name: 'message 1',
|
|
type: 'json'
|
|
}
|
|
]
|
|
},
|
|
settings: {
|
|
encodeUrl: false,
|
|
timeout: 30
|
|
}
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe('body:grpc', () => {
|
|
it('parses message content with name and content', () => {
|
|
const input = `
|
|
body:grpc {
|
|
name: message 1
|
|
content: '''
|
|
{"foo":"bar"}
|
|
'''
|
|
}
|
|
`;
|
|
|
|
const expected = {
|
|
body: {
|
|
mode: 'grpc',
|
|
grpc: [
|
|
{
|
|
content: '{"foo":"bar"}',
|
|
name: 'message 1'
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('parses message with variables in content', () => {
|
|
const input = `
|
|
body:grpc {
|
|
name: message 1
|
|
content: '''
|
|
{"id":{{userId}},"name":"{{userName}}"}
|
|
'''
|
|
}
|
|
`;
|
|
|
|
const expected = {
|
|
body: {
|
|
mode: 'grpc',
|
|
grpc: [
|
|
{
|
|
content: '{"id":{{userId}},"name":"{{userName}}"}',
|
|
name: 'message 1'
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe('multi-line values', () => {
|
|
it('parses multi-line values in URL, headers, params, and vars', () => {
|
|
const input = `
|
|
meta {
|
|
name: new-line
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
get {
|
|
url: '''
|
|
https://httpbin.io/anything?foo=hello
|
|
world
|
|
'''
|
|
body: none
|
|
auth: oauth2
|
|
}
|
|
|
|
params:query {
|
|
foo: '''
|
|
hello
|
|
world
|
|
'''
|
|
}
|
|
|
|
headers {
|
|
"test header": '''
|
|
t1
|
|
t2
|
|
'''
|
|
}
|
|
|
|
vars:pre-request {
|
|
test-var: '''
|
|
t1
|
|
t2
|
|
'''
|
|
}
|
|
`;
|
|
|
|
const expected = {
|
|
meta: {
|
|
name: 'new-line',
|
|
type: 'http',
|
|
seq: '1'
|
|
},
|
|
http: {
|
|
method: 'get',
|
|
url: 'https://httpbin.io/anything?foo=hello\nworld',
|
|
body: 'none',
|
|
auth: 'oauth2'
|
|
},
|
|
params: [
|
|
{
|
|
name: 'foo',
|
|
value: 'hello\nworld',
|
|
enabled: true,
|
|
type: 'query'
|
|
}
|
|
],
|
|
headers: [
|
|
{
|
|
name: 'test header',
|
|
value: 't1\nt2',
|
|
enabled: true
|
|
}
|
|
],
|
|
vars: {
|
|
req: [
|
|
{
|
|
name: 'test-var',
|
|
value: 't1\nt2',
|
|
enabled: true,
|
|
local: false
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('parses multiline body parts with content type annotation', () => {
|
|
const input = `
|
|
body:multipart-form {
|
|
filePart: '''
|
|
Line1
|
|
Line2
|
|
''' @contentType(text/plain)
|
|
}
|
|
`;
|
|
|
|
const expected = {
|
|
body: {
|
|
multipartForm: [
|
|
{
|
|
name: 'filePart',
|
|
value: 'Line1\nLine2',
|
|
enabled: true,
|
|
type: 'text',
|
|
contentType: 'text/plain'
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
});
|
|
});
|