From 4464dd1e6b38e6840964136c692e576418e25b05 Mon Sep 17 00:00:00 2001 From: Max Kurapov Date: Fri, 21 Jun 2024 20:35:46 +0200 Subject: [PATCH] chore(bruno): add conditionals to post-request scripts to not hide errors --- .../Continuation Request.bru | 6 ++-- .../Create Incoming Payment.bru | 28 +++++++++++-------- .../Create Outgoing Payment.bru | 9 +++--- .../Get receiver wallet address.bru | 6 +++- .../Get sender wallet address.bru | 7 ++++- .../Open Payments/Continuation Request.bru | 6 ++-- .../Open Payments/Create Incoming Payment.bru | 5 +++- .../Open Payments/Create Outgoing Payment.bru | 5 +++- .../Examples/Open Payments/Create Quote.bru | 8 ++++-- .../Get receiver wallet address.bru | 8 ++++-- .../Get sender wallet address.bru | 6 +++- .../Web Monetization/Continuation Request.bru | 6 ++-- .../Create Incoming Payment.bru | 25 +++++++++-------- .../Create Outgoing Payment 1.bru | 6 ++-- .../Create Outgoing Payment 2.bru | 4 ++- .../Create Outgoing Payment 3.bru | 4 ++- .../Get receiver wallet address.bru | 7 ++++- .../Get sender wallet address.bru | 6 +++- .../Create Incoming Payment.bru | 5 +++- .../Create Outgoing Payment.bru | 5 +++- .../Quotes/Create Quote.bru | 10 ++++--- bruno/collections/Rafiki/scripts.js | 14 +++++++--- 22 files changed, 123 insertions(+), 63 deletions(-) diff --git a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Continuation Request.bru b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Continuation Request.bru index c75d5df7ea..01d39ebf3f 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Continuation Request.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Continuation Request.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Incoming Payment.bru b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Incoming Payment.bru index 1851537335..6fffd0742c 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Incoming Payment.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Incoming Payment.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Outgoing Payment.bru b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Outgoing Payment.bru index 5095764d0f..4d9e3a2a63 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Create Outgoing Payment.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get receiver wallet address.bru b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get receiver wallet address.bru index 8f2e84a2ee..5b9b0277a9 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get receiver wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get receiver wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get sender wallet address.bru b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get sender wallet address.bru index fe4b6f2fd3..384cfa6282 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get sender wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments Without Quote/Get sender wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Continuation Request.bru b/bruno/collections/Rafiki/Examples/Open Payments/Continuation Request.bru index c75d5df7ea..01d39ebf3f 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Continuation Request.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Continuation Request.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Create Incoming Payment.bru b/bruno/collections/Rafiki/Examples/Open Payments/Create Incoming Payment.bru index 553c9ef622..afc6464ee6 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Create Incoming Payment.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Create Incoming Payment.bru @@ -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()); + } } diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Create Outgoing Payment.bru b/bruno/collections/Rafiki/Examples/Open Payments/Create Outgoing Payment.bru index 58601494f7..e14eaa6536 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Create Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Create Outgoing Payment.bru @@ -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()); + } } diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Create Quote.bru b/bruno/collections/Rafiki/Examples/Open Payments/Create Quote.bru index f7c3ea5995..a7708217f4 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Create Quote.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Create Quote.bru @@ -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)) + } } diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Get receiver wallet address.bru b/bruno/collections/Rafiki/Examples/Open Payments/Get receiver wallet address.bru index 8f2e84a2ee..9e5acc50c4 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Get receiver wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Get receiver wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Examples/Open Payments/Get sender wallet address.bru b/bruno/collections/Rafiki/Examples/Open Payments/Get sender wallet address.bru index fe4b6f2fd3..9665a40e32 100644 --- a/bruno/collections/Rafiki/Examples/Open Payments/Get sender wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Open Payments/Get sender wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Continuation Request.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Continuation Request.bru index c75d5df7ea..01d39ebf3f 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Continuation Request.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Continuation Request.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Create Incoming Payment.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Create Incoming Payment.bru index 360ad36aea..071e7df0be 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Create Incoming Payment.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Create Incoming Payment.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 1.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 1.bru index d05b060e22..6bdb591816 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 1.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 1.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 2.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 2.bru index 32cce4c122..6dce96ac06 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 2.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 2.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 3.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 3.bru index a37a54d190..814d2171de 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 3.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Create Outgoing Payment 3.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Get receiver wallet address.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Get receiver wallet address.bru index 8f2e84a2ee..d59f39b24f 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Get receiver wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Get receiver wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Examples/Web Monetization/Get sender wallet address.bru b/bruno/collections/Rafiki/Examples/Web Monetization/Get sender wallet address.bru index fe4b6f2fd3..9665a40e32 100644 --- a/bruno/collections/Rafiki/Examples/Web Monetization/Get sender wallet address.bru +++ b/bruno/collections/Rafiki/Examples/Web Monetization/Get sender wallet address.bru @@ -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) diff --git a/bruno/collections/Rafiki/Open Payments APIs/Incoming Payments/Create Incoming Payment.bru b/bruno/collections/Rafiki/Open Payments APIs/Incoming Payments/Create Incoming Payment.bru index c72e3cd91f..c718828e1c 100644 --- a/bruno/collections/Rafiki/Open Payments APIs/Incoming Payments/Create Incoming Payment.bru +++ b/bruno/collections/Rafiki/Open Payments APIs/Incoming Payments/Create Incoming Payment.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Open Payments APIs/Outgoing Payments/Create Outgoing Payment.bru b/bruno/collections/Rafiki/Open Payments APIs/Outgoing Payments/Create Outgoing Payment.bru index c0e404ad13..62ec4793f7 100644 --- a/bruno/collections/Rafiki/Open Payments APIs/Outgoing Payments/Create Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Open Payments APIs/Outgoing Payments/Create Outgoing Payment.bru @@ -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 { diff --git a/bruno/collections/Rafiki/Open Payments APIs/Quotes/Create Quote.bru b/bruno/collections/Rafiki/Open Payments APIs/Quotes/Create Quote.bru index 9059ff40f9..1e53624a2c 100644 --- a/bruno/collections/Rafiki/Open Payments APIs/Quotes/Create Quote.bru +++ b/bruno/collections/Rafiki/Open Payments APIs/Quotes/Create Quote.bru @@ -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 { diff --git a/bruno/collections/Rafiki/scripts.js b/bruno/collections/Rafiki/scripts.js index d53ba17b91..8ea6b7a614 100644 --- a/bruno/collections/Rafiki/scripts.js +++ b/bruno/collections/Rafiki/scripts.js @@ -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 () {