From 4d8c3771433d8dc69696f583caf1613bed0be8ed Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Thu, 1 Feb 2024 16:49:48 +0530 Subject: [PATCH] test: added local module scripting example --- packages/bruno-tests/collection/lib/math.js | 5 +++ .../scripting/local modules/sum.bru | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 packages/bruno-tests/collection/lib/math.js create mode 100644 packages/bruno-tests/collection/scripting/local modules/sum.bru diff --git a/packages/bruno-tests/collection/lib/math.js b/packages/bruno-tests/collection/lib/math.js new file mode 100644 index 000000000..da6a05ef3 --- /dev/null +++ b/packages/bruno-tests/collection/lib/math.js @@ -0,0 +1,5 @@ +const sum = (a, b) => a + b; + +module.exports = { + sum +}; diff --git a/packages/bruno-tests/collection/scripting/local modules/sum.bru b/packages/bruno-tests/collection/scripting/local modules/sum.bru new file mode 100644 index 000000000..c0c9a1aeb --- /dev/null +++ b/packages/bruno-tests/collection/scripting/local modules/sum.bru @@ -0,0 +1,42 @@ +meta { + name: sum + type: http + seq: 1 +} + +post { + url: {{host}}/api/echo/json + body: json + auth: none +} + +body:json { + { + "a": 1, + "b": 2 + } +} + +assert { + res.status: eq 200 +} + +script:pre-request { + const math = require("./lib/math"); + + const body = req.getBody(); + body.sum = body.a + body.b; + + req.setBody(body); +} + +tests { + test("should return json", function() { + const data = res.getBody(); + expect(res.getBody()).to.eql({ + "a": 1, + "b": 2, + "sum": 3 + }); + }); +}