diff --git a/packages/bruno-converters/src/postman/postman-translations.js b/packages/bruno-converters/src/postman/postman-translations.js index bc6b0ffb1..b741cd3b2 100644 --- a/packages/bruno-converters/src/postman/postman-translations.js +++ b/packages/bruno-converters/src/postman/postman-translations.js @@ -15,11 +15,17 @@ const replacements = { 'pm\\.expect\\(': 'expect(', 'pm\\.environment\\.has\\(([^)]+)\\)': 'bru.getEnvVar($1) !== undefined && bru.getEnvVar($1) !== null', 'pm\\.response\\.code': 'res.getStatus()', - 'pm\\.response\\.text\\(': 'res.getBody()?.toString(', + 'pm\\.response\\.text\\(\\)': 'JSON.stringify(res.getBody())', 'pm\\.expect\\.fail\\(': 'expect.fail(', 'pm\\.response\\.responseTime': 'res.getResponseTime()', 'pm\\.environment\\.name': 'bru.getEnvName()', + 'pm\\.response\\.status': 'res.statusText', + 'pm\\.response\\.headers': 'req.getHeaders()', "tests\\['([^']+)'\\]\\s*=\\s*([^;]+);": 'test("$1", function() { expect(Boolean($2)).to.be.true; });', + 'pm\\.request\\.url': 'req.getUrl()', + 'pm\\.request\\.method': 'req.getMethod()', + 'pm\\.request\\.headers': 'req.getHeaders()', + 'pm\\.request\\.body': 'req.getBody()', // deprecated translations 'postman\\.setEnvironmentVariable\\(': 'bru.setEnvVar(', 'postman\\.getEnvironmentVariable\\(': 'bru.getEnvVar(', diff --git a/packages/bruno-converters/tests/postman/postman-translations.spec.js b/packages/bruno-converters/tests/postman/postman-translations.spec.js index 95a2c96f9..a2fcf1560 100644 --- a/packages/bruno-converters/tests/postman/postman-translations.spec.js +++ b/packages/bruno-converters/tests/postman/postman-translations.spec.js @@ -137,17 +137,3 @@ describe('postmanTranslation function', () => { expect(postmanTranslation(inputScript)).toBe(expectedOutput); }); }); - -test('should handle response commands', () => { - const inputScript = ` - const responseTime = pm.response.responseTime; - const responseCode = pm.response.code; - const responseText = pm.response.text(); - `; - const expectedOutput = ` - const responseTime = res.getResponseTime(); - const responseCode = res.getStatus(); - const responseText = res.getBody()?.toString(); - `; - expect(postmanTranslation(inputScript)).toBe(expectedOutput); -}); diff --git a/packages/bruno-converters/tests/postman/postman-translations/postman-request.spec.js b/packages/bruno-converters/tests/postman/postman-translations/postman-request.spec.js new file mode 100644 index 000000000..5b1305f73 --- /dev/null +++ b/packages/bruno-converters/tests/postman/postman-translations/postman-request.spec.js @@ -0,0 +1,27 @@ +const { default: postmanTranslation } = require("../../../src/postman/postman-translations"); + +describe('postmanTranslations - request commands', () => { + test('should handle request commands', () => { + const inputScript = ` + const requestUrl = pm.request.url; + const requestMethod = pm.request.method; + const requestHeaders = pm.request.headers; + const requestBody = pm.request.body; + + pm.test('Request method is POST', function() { + pm.expect(pm.request.method).to.equal('POST'); + }); + `; + const expectedOutput = ` + const requestUrl = req.getUrl(); + const requestMethod = req.getMethod(); + const requestHeaders = req.getHeaders(); + const requestBody = req.getBody(); + + test('Request method is POST', function() { + expect(req.getMethod()).to.equal('POST'); + }); + `; + expect(postmanTranslation(inputScript)).toBe(expectedOutput); + }); +}); \ No newline at end of file diff --git a/packages/bruno-converters/tests/postman/postman-translations/postman-response.spec.js b/packages/bruno-converters/tests/postman/postman-translations/postman-response.spec.js new file mode 100644 index 000000000..6e54af13b --- /dev/null +++ b/packages/bruno-converters/tests/postman/postman-translations/postman-response.spec.js @@ -0,0 +1,34 @@ +const { default: postmanTranslation } = require("../../../src/postman/postman-translations"); + +describe('postmanTranslations - response commands', () => { + test('should handle response commands', () => { + const inputScript = ` + const responseTime = pm.response.responseTime; + const responseCode = pm.response.code; + const responseText = pm.response.text(); + const responseJson = pm.response.json(); + const responseStatus = pm.response.status; + const responseHeaders = pm.response.headers; + + pm.test('Status code is 200', function() { + pm.response.to.have.status(200); + }); + `; + const expectedOutput = ` + const responseTime = res.getResponseTime(); + const responseCode = res.getStatus(); + const responseText = JSON.stringify(res.getBody()); + const responseJson = res.getBody(); + const responseStatus = res.statusText; + const responseHeaders = req.getHeaders(); + + test('Status code is 200', function() { + expect(res.getStatus()).to.equal(200); + }); + `; + expect(postmanTranslation(inputScript)).toBe(expectedOutput); + }); +}); + + +