test: added local module scripting example

This commit is contained in:
Anoop M D 2024-02-01 16:49:48 +05:30
parent 7b6c72c63b
commit 4d8c377143
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,5 @@
const sum = (a, b) => a + b;
module.exports = {
sum
};

View File

@ -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
});
});
}