diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/array.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/array.bru new file mode 100644 index 000000000..7e3492abe --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/array.bru @@ -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") + + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/boolean.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/boolean.bru new file mode 100644 index 000000000..28513d679 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/boolean.bru @@ -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; + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/folder.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/folder.bru new file mode 100644 index 000000000..4e66417c7 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/folder.bru @@ -0,0 +1,3 @@ +meta { + name: setBody +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/null.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/null.bru new file mode 100644 index 000000000..8d8d2dcf5 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/null.bru @@ -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; + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/number.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/number.bru new file mode 100644 index 000000000..a90aec802 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/number.bru @@ -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); + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/object.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/object.bru new file mode 100644 index 000000000..02ad78a2e --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/object.bru @@ -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"); + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/string.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/string.bru new file mode 100644 index 000000000..a87e57bd4 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/string.bru @@ -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"); + }); + +} diff --git a/packages/bruno-tests/collection/scripting/api/res/setBody/undefined.bru b/packages/bruno-tests/collection/scripting/api/res/setBody/undefined.bru new file mode 100644 index 000000000..0dc918f1f --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/res/setBody/undefined.bru @@ -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; + }); + +}