From 3b3fa8a8565268594b5303c9304bb4f1ccfcfe61 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Mon, 12 Aug 2024 13:10:21 +0530 Subject: [PATCH] feat: safe mode updates --- .../axios/axios-pre-req-script.bru | 34 +++++++++++++++++++ .../collection/scripting/js/setTimeout.bru | 32 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 packages/bruno-tests/collection/scripting/inbuilt modules/axios/axios-pre-req-script.bru create mode 100644 packages/bruno-tests/collection/scripting/js/setTimeout.bru diff --git a/packages/bruno-tests/collection/scripting/inbuilt modules/axios/axios-pre-req-script.bru b/packages/bruno-tests/collection/scripting/inbuilt modules/axios/axios-pre-req-script.bru new file mode 100644 index 000000000..1998c9665 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/inbuilt modules/axios/axios-pre-req-script.bru @@ -0,0 +1,34 @@ +meta { + name: axios-pre-req-script + type: http + seq: 1 +} + +get { + url: {{host}}/ping + body: none + auth: none +} + +script:pre-request { + const axios = require("axios"); + + const url = "https://testbench-sanity.usebruno.com/api/echo/json"; + const response = await axios.post(url, { + "hello": "bruno" + }); + + req.setBody(response.data); + req.setMethod("POST"); + req.setUrl(url); +} + +tests { + test("req.getBody()", function() { + const data = res.getBody(); + expect(data).to.eql({ + "hello": "bruno" + }); + }); + +} diff --git a/packages/bruno-tests/collection/scripting/js/setTimeout.bru b/packages/bruno-tests/collection/scripting/js/setTimeout.bru new file mode 100644 index 000000000..8b136a113 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/js/setTimeout.bru @@ -0,0 +1,32 @@ +meta { + name: setTimeout + type: http + seq: 1 +} + +get { + url: {{host}}/ping + body: none + auth: none +} + +script:pre-request { + bru.setVar("test-js-set-timeout", ""); + await new Promise((resolve, reject) => { + setTimeout(() => { + bru.setVar("test-js-set-timeout", "bruno"); + resolve(); + }, 1000); + }); + + const v = bru.getVar("test-js-set-timeout"); + bru.setVar("test-js-set-timeout", v + "-is-awesome"); + +} + +tests { + test("setTimeout()", function() { + const v = bru.getVar("test-js-set-timeout") + expect(v).to.eql("bruno-is-awesome"); + }); +}