Skip to content
Merged
Changes from 2 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
27 changes: 27 additions & 0 deletions packages/request-client.js/test/declarative-payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ describe('request-client.js: declarative payments', () => {
expect(requestData.balance!.balance).toEqual('10');
});

it('allows to create a request and declare a received payment in the same transaction', async () => {
const requestNetwork = new RequestNetwork({
useMockStorage: true,
signatureProvider: TestData.fakeSignatureProvider,
});
const request = await requestNetwork.createRequest({
...requestCreationParams,
requestInfo: {
...TestData.parametersWithoutExtensionsData,
extensionsData: [
{
action: ExtensionTypes.PnAnyDeclarative.ACTION.DECLARE_RECEIVED_PAYMENT,
id: ExtensionTypes.PAYMENT_NETWORK_ID.ANY_DECLARATIVE,
parameters: {
amount: '10',
note: 'received payment',
txhash: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
network: 'mainnet',
},
},
],
},
});
const requestData = await request.waitForConfirmation();
expect(requestData.balance!.balance).toEqual('10');
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using non-null assertions.

The non-null assertion operator (!) is used on requestData.balance!.balance. It's safer to use optional chaining (?.) to avoid potential runtime errors.

- expect(requestData.balance!.balance).toEqual('10');
+ expect(requestData.balance?.balance).toEqual('10');
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(requestData.balance!.balance).toEqual('10');
expect(requestData.balance?.balance).toEqual('10');
Tools
Biome

[error] 217-217: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

});

it('allows to declare a sent refund', async () => {
const requestNetwork = new RequestNetwork({
httpConfig,
Expand Down