mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34:15 +01:00
test: added local module scripting example
This commit is contained in:
parent
7b6c72c63b
commit
4d8c377143
5
packages/bruno-tests/collection/lib/math.js
Normal file
5
packages/bruno-tests/collection/lib/math.js
Normal file
@ -0,0 +1,5 @@
|
||||
const sum = (a, b) => a + b;
|
||||
|
||||
module.exports = {
|
||||
sum
|
||||
};
|
@ -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
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user