Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,34 @@ body:graphql:vars {

script:pre-request {
// Create an additional wallet address to represent the account that will be sending money

const fetch = require('node-fetch');
const scripts = require('./scripts');

const randomInt = Math.floor(Math.random() * (1001));

const initialRequest = bru.getEnvVar("initialWalletAddressRequest");
const postRequestBody = {
query: initialRequest.body.query,
variables: {
"input": {
"assetId": bru.getEnvVar("assetId"),
"url": "https://" + bru.getEnvVar("OpenPaymentsHost") + "/simon/" + randomInt,
"publicName": "Simon"

const createWalletAddressQuery = `
mutation CreateWalletAddress($input: CreateWalletAddressInput!) {
createWalletAddress(input: $input) {
walletAddress {
id
}
}
}
`;

const postRequestBody = {
query: createWalletAddressQuery,
variables: {
input: {
assetId: bru.getEnvVar("assetId"),
url: "https://" + bru.getEnvVar("OpenPaymentsHost") + "/simon/" + randomInt,
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pre-request script builds the wallet address URL using bru.getEnvVar("OpenPaymentsHost"), but this env var isn’t defined anywhere in the repository’s Rafiki Bruno environments (only senderOpenPaymentsHost / receiverOpenPaymentsHost patterns are used elsewhere). This likely produces https://undefined/... URLs by default. Consider switching to an existing env var that is actually set in the collection flow (e.g., the sender Open Payments host) or adding OpenPaymentsHost to the committed environment templates/docs so the request is reproducible.

Suggested change
url: "https://" + bru.getEnvVar("OpenPaymentsHost") + "/simon/" + randomInt,
url: "https://" + bru.getEnvVar("senderOpenPaymentsHost") + "/simon/" + randomInt,

Copilot uses AI. Check for mistakes.
publicName: "Simon"
}
}

const signature = scripts.generateBackendApiSignature(postRequestBody)
};

const signature = scripts.generateBackendApiSignature(postRequestBody);
const postRequest = {
method: 'post',
headers: {
Expand All @@ -79,11 +88,12 @@ script:pre-request {
},
body: JSON.stringify(postRequestBody)
};

const response = await fetch(`${initialRequest.url}`, postRequest);

const graphqlUrl = bru.getEnvVar("RafikiGraphqlHost") + "/graphql";
const response = await fetch(graphqlUrl, postRequest);
const body = await response.json();
bru.setEnvVar("secondWalletAddressId", body.data.createWalletAddress.walletAddress.id);
Comment on lines +92 to 95
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script assumes the wallet-address creation succeeded and immediately dereferences body.data.createWalletAddress.walletAddress.id. If the fetch fails (non-2xx) or the GraphQL response contains errors (no data), this will throw a TypeError and obscure the real failure. Add a check for response.ok and/or body?.data?.createWalletAddress (and surface body.errors in the thrown error) before setting secondWalletAddressId.

Copilot uses AI. Check for mistakes.

scripts.addApiSignatureHeader();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ script:post-response {
if (body?.data) {
bru.setEnvVar("walletAddressId", body.data.createWalletAddress.walletAddress.id);
bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.url);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walletAddressUrl is being set from body.data.createWalletAddress.walletAddress.url, but the GraphQL selection set for walletAddress in this request does not include a url field (it includes address instead). In GraphQL, omitted fields won’t be present in the response, so this will be undefined and the included tests will fail. Align the selection set and the post-response mapping (either request url explicitly if it exists in the schema, or set walletAddressUrl from the selected address field / rename the env var accordingly).

Suggested change
bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.url);
bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.address);

Copilot uses AI. Check for mistakes.
bru.setEnvVar('initialWalletAddressRequest',req)
}
}

Expand Down
Loading