2023-02-03 16:38:40 +01:00
|
|
|
const bruToJsonV2 = require("../src/index");
|
|
|
|
|
|
|
|
const assertSingleHeader = (input) => {
|
|
|
|
const output = bruToJsonV2(input);
|
|
|
|
|
|
|
|
const expected = {
|
|
|
|
"headers": [{
|
|
|
|
"name": "hello",
|
|
|
|
"value": "world",
|
|
|
|
"enabled": true
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("headers parser", () => {
|
|
|
|
it("should parse empty header", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
}`;
|
|
|
|
|
|
|
|
const output = bruToJsonV2(input);
|
|
|
|
const expected = {
|
|
|
|
"headers": []
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse single header", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
hello: world
|
|
|
|
}`;
|
|
|
|
|
|
|
|
assertSingleHeader(input);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse single header with spaces", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
hello: world
|
|
|
|
}`;
|
|
|
|
|
|
|
|
assertSingleHeader(input);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse single header with spaces and newlines", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
|
|
|
|
hello: world
|
|
|
|
|
|
|
|
|
|
|
|
}`;
|
|
|
|
|
|
|
|
assertSingleHeader(input);
|
|
|
|
});
|
|
|
|
|
2023-02-03 18:32:16 +01:00
|
|
|
it("should parse single header with empty value", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
hello:
|
|
|
|
}`;
|
|
|
|
|
|
|
|
const output = bruToJsonV2(input);
|
|
|
|
const expected = {
|
|
|
|
"headers": [{
|
|
|
|
"name": "hello",
|
|
|
|
"value": "",
|
|
|
|
"enabled": true
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
2023-02-03 16:38:40 +01:00
|
|
|
it("should parse multi headers", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
2023-02-03 17:14:07 +01:00
|
|
|
content-type: application/json
|
|
|
|
Authorization: JWT secret
|
2023-02-03 16:38:40 +01:00
|
|
|
}`;
|
|
|
|
|
|
|
|
const output = bruToJsonV2(input);
|
|
|
|
const expected = {
|
|
|
|
"headers": [{
|
2023-02-03 17:14:07 +01:00
|
|
|
"name": "content-type",
|
|
|
|
"value": "application/json",
|
2023-02-03 16:38:40 +01:00
|
|
|
"enabled": true
|
|
|
|
}, {
|
2023-02-03 17:14:07 +01:00
|
|
|
"name": "Authorization",
|
|
|
|
"value": "JWT secret",
|
2023-02-03 16:38:40 +01:00
|
|
|
"enabled": true
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should throw error on invalid header", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
hello: world
|
|
|
|
foo
|
|
|
|
}`;
|
|
|
|
|
|
|
|
expect(() => bruToJsonV2(input)).toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should throw error on invalid header", () => {
|
|
|
|
const input = `
|
|
|
|
headers {
|
|
|
|
hello: world
|
|
|
|
foo: bar}`;
|
|
|
|
|
|
|
|
expect(() => bruToJsonV2(input)).toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|