Skip to content

Commit

Permalink
chore(bruno): add conditionals to post-request scripts to not hide er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
mkurapov committed Jun 21, 2024
1 parent e1d8c73 commit 4464dd1
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ script:pre-request {
}

script:post-response {
const body = res.getBody();
bru.setEnvVar("accessToken", body.access_token.value);
bru.setEnvVar("tokenId", body.access_token.manage.split('/').pop())
const scripts = require('./scripts');

scripts.storeTokenDetails();
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
bru.setEnvVar("incomingPaymentUrl", body.id);

bru.setEnvVar("debitAmount", JSON.stringify({
"value": "500",
"assetCode": "USD",
"assetScale": 2
}))
if (body?.id) {
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
bru.setEnvVar("incomingPaymentUrl", body.id);

bru.setEnvVar("debitAmount", JSON.stringify({
"value": "500",
"assetCode": "USD",
"assetScale": 2
}))

bru.setEnvVar("receiveAmount", JSON.stringify({
"value": "500",
"assetCode": "USD",
"assetScale": 2
}))
}

bru.setEnvVar("receiveAmount", JSON.stringify({
"value": "500",
"assetCode": "USD",
"assetScale": 2
}))
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
console.log(res.status)
console.log(res.statusText)
console.log({body})
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());


if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ script:pre-request {
script:post-response {
const url = require('url')

const body = res.body
if (res.getStatus() !== 200) {
return
}

const body = res.getBody()
bru.setEnvVar("receiverAssetCode", body?.assetCode)
bru.setEnvVar("receiverAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ script:pre-request {
script:post-response {
const url = require('url')

const body = res.body
if (res.getStatus() !== 200) {
return
}

const body = res.getBody()

bru.setEnvVar("senderAssetCode", body?.assetCode)
bru.setEnvVar("senderAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ script:pre-request {
}

script:post-response {
const body = res.getBody();
bru.setEnvVar("accessToken", body.access_token.value);
bru.setEnvVar("tokenId", body.access_token.manage.split('/').pop())
const scripts = require('./scripts');

scripts.storeTokenDetails();
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("quoteId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify(body.debitAmount))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify(body.receiveAmount))
if (body?.id) {
bru.setEnvVar("quoteId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify(body.debitAmount))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify(body.receiveAmount))
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ script:pre-request {

script:post-response {
const url = require('url')

const body = res.body

if (res.getStatus() !== 200) {
return
}

const body = res.getBody()
bru.setEnvVar("receiverAssetCode", body?.assetCode)
bru.setEnvVar("receiverAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ script:pre-request {
script:post-response {
const url = require('url')

const body = res.body
if (res.getStatus() !== 200) {
return
}

const body = res.getBody()
bru.setEnvVar("senderAssetCode", body?.assetCode)
bru.setEnvVar("senderAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ script:pre-request {
}

script:post-response {
const body = res.getBody();
bru.setEnvVar("accessToken", body.access_token.value);
bru.setEnvVar("tokenId", body.access_token.manage.split('/').pop())
const scripts = require('./scripts');

scripts.storeTokenDetails();
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify({
value: "99999999999999",
assetCode: "USD",
assetScale: 2
}))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify({
value: "99999999999999",
assetCode: "USD",
assetScale: 2
}))

if (body?.id) {
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify({
value: "99999999999999",
assetCode: "USD",
assetScale: 2
}))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify({
value: "99999999999999",
assetCode: "USD",
assetScale: 2
}))
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());


if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ script:pre-request {
script:post-response {
const url = require('url')

const body = res.body
if (res.getStatus() !== 200) {
return
}

const body = res.getBody()

bru.setEnvVar("receiverAssetCode", body?.assetCode)
bru.setEnvVar("receiverAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ script:pre-request {
script:post-response {
const url = require('url')

const body = res.body
if (res.getStatus() !== 200) {
return
}

const body = res.getBody()
bru.setEnvVar("senderAssetCode", body?.assetCode)
bru.setEnvVar("senderAssetScale", body?.assetScale)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("incomingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());

if (body?.id) {
bru.setEnvVar("outgoingPaymentId", body.id.split("/").pop());
}
}

tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ script:pre-request {

script:post-response {
const body = res.getBody();
bru.setEnvVar("quoteId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify(body.debitAmount))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify(body.receiveAmount))


if (body?.id) {
bru.setEnvVar("quoteId", body.id.split("/").pop());
bru.setEnvVar("quoteDebitAmount", JSON.stringify(body.debitAmount))
bru.setEnvVar("quoteReceiveAmount", JSON.stringify(body.receiveAmount))
}
}

tests {
Expand Down
14 changes: 10 additions & 4 deletions bruno/collections/Rafiki/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ const scripts = {

storeTokenDetails: function () {
const body = res.getBody()
bru.setEnvVar('accessToken', body?.access_token?.value)
bru.setEnvVar('continueToken', body.continue.access_token.value)
bru.setEnvVar('continueId', body.continue.uri.split('/').pop())
bru.setEnvVar('tokenId', body?.access_token?.manage.split('/').pop())

if (body?.access_token) {
bru.setEnvVar('accessToken', body.access_token.value)
bru.setEnvVar('tokenId', body.access_token.manage.split('/').pop())
}

if (body?.continue) {
bru.setEnvVar('continueToken', body.continue.access_token.value)
bru.setEnvVar('continueId', body.continue.uri.split('/').pop())
}
},

loadWalletAddressIdsIntoVariables: async function () {
Expand Down

0 comments on commit 4464dd1

Please sign in to comment.