2023-09-21 21:12:48 +02:00
|
|
|
const bruToJson = require('../src/bruToJson');
|
2023-02-05 20:57:08 +01:00
|
|
|
|
2023-09-21 21:12:48 +02:00
|
|
|
describe('defaults', () => {
|
|
|
|
it('should parse the default type and seq', () => {
|
2023-02-05 20:57:08 +01:00
|
|
|
const input = `
|
|
|
|
meta {
|
|
|
|
name: Create user
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
url: /users
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const expected = {
|
2023-09-21 21:12:48 +02:00
|
|
|
meta: {
|
|
|
|
name: 'Create user',
|
|
|
|
seq: 1,
|
|
|
|
type: 'http'
|
2023-02-05 20:57:08 +01:00
|
|
|
},
|
2023-09-21 21:12:48 +02:00
|
|
|
http: {
|
|
|
|
method: 'post',
|
|
|
|
url: '/users'
|
2023-02-05 20:57:08 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const output = bruToJson(input);
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
2023-09-21 21:12:48 +02:00
|
|
|
it('should parse the default body mode as json if the body is found', () => {
|
2023-02-05 20:57:08 +01:00
|
|
|
const input = `
|
|
|
|
meta {
|
|
|
|
name: Create user
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
url: /users
|
|
|
|
}
|
|
|
|
|
|
|
|
body {
|
|
|
|
{
|
|
|
|
name: John
|
|
|
|
age: 30
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const expected = {
|
2023-09-21 21:12:48 +02:00
|
|
|
meta: {
|
|
|
|
name: 'Create user',
|
|
|
|
seq: 1,
|
|
|
|
type: 'http'
|
2023-02-05 20:57:08 +01:00
|
|
|
},
|
2023-09-21 21:12:48 +02:00
|
|
|
http: {
|
|
|
|
method: 'post',
|
|
|
|
url: '/users',
|
|
|
|
body: 'json'
|
2023-02-05 20:57:08 +01:00
|
|
|
},
|
2023-09-21 21:12:48 +02:00
|
|
|
body: {
|
|
|
|
json: '{\n name: John\n age: 30\n}'
|
2023-02-05 20:57:08 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const output = bruToJson(input);
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|