mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 11:51:30 +00:00
feat: add setBody test script to bruno-tests collection (#4415)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
meta {
|
||||
name: array
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
const obj = {
|
||||
hello : "hello from post-res"
|
||||
}
|
||||
// Safe mode, Dev mode behaves differently, null is getting converted to undefined, although both have null in the response, tests with undefined fails in safe mode, this needs to be investigated,, undefined is not a valid JSON
|
||||
res.setBody(["hello",1, null, undefined, true, obj])
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(array)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body.length).to.eql(6);
|
||||
expect(body[0]).to.eql("hello")
|
||||
expect(body[1]).to.eql(1)
|
||||
expect(body[2]).to.be.null
|
||||
// Safe mode, Dev mode behaves differently, null is getting converted to undefined, although both have null in the response, tests with undefined fails in safe mode, this needs to be investigated,, undefined is not a valid JSON
|
||||
expect(body[3]).to.be.undefined;
|
||||
expect(body[4]).to.eql(true)
|
||||
expect(body[5].hello).to.eql("hello from post-res")
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: boolean
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
res.setBody(true)
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(boolean)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body).to.be.true;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
meta {
|
||||
name: setBody
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: null
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
res.setBody(null)
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(null)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body).to.be.null;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: number
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
res.setBody(2)
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(number)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body).to.eql(2);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
meta {
|
||||
name: object
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
res.setBody({
|
||||
hello : "hello from post-res"
|
||||
})
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(object)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body.hello).to.eql("hello from post-res");
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: string
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
res.setBody("hello from post-res")
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(string)", function() {
|
||||
const body = res.getBody();
|
||||
expect(body).to.eql("hello from post-res");
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
meta {
|
||||
name: undefined
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
// if undefined is not passed to res.setBody() the test fails in only safe-mode, needs to check, undefined is not a valid JSON
|
||||
// Safe mode, Dev mode behaves differently, null is getting converted to undefined, although both have null in the response, tests with undefined fails in safe mode, this needs to be investigated, undefined is not a valid JSON
|
||||
res.setBody(undefined)
|
||||
}
|
||||
|
||||
tests {
|
||||
test("res.setBody(undefined)", function() {
|
||||
const body = res.getBody();
|
||||
// Safe mode, Dev mode behaves differently, null is getting converted to undefined, although both have null in the response, tests with undefined fails in safe mode, this needs to be investigated, undefined is not a valid JSON
|
||||
expect(body).to.be.undefined;
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user