Skip to content

Commit

Permalink
Merge pull request #2006 from myxmaster/fix-lnurl-test
Browse files Browse the repository at this point in the history
Fixed lnurl test
  • Loading branch information
kaloudis authored Feb 29, 2024
2 parents 25bbdf5 + 5072605 commit 761bebd
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions utils/handleAnything.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ jest.mock('../stores/Stores', () => ({
invoicesStore: { getPayReq: jest.fn() }
}));
jest.mock('react-native-blob-util', () => ({}));
// jest.mock('', () => ({ getParams: () => ({}) }));
jest.mock('js-lnurl', () => ({
getParams: () => mockGetLnurlParams
}));
import stores from '../stores/Stores';
import handleAnything from './handleAnything';
let mockProcessedSendAddress = {};
let mockIsValidBitcoinAddress = false;
let mockIsValidLightningPubKey = false;
let mockIsValidLightningPaymentRequest = false;
let mockSupportsOnchainSends = true;
let mockGetLnurlParams = {};

describe('handleAnything', () => {
beforeEach(() => {
Expand Down Expand Up @@ -116,42 +119,30 @@ describe('handleAnything', () => {
describe('bitcoin URI with lnurl and backend not supporting on-chain sends', () => {
// test needs to be mocked out more as endpoint at https://ts.dergigi.com/BTC/UILNURL/pay/i/Wg7JV2ZFHs4cschM6bG5PT
// returns {"status":"ERROR","reason":"Invoice not in a valid payable state"} and throws on handleAnything.ts:54
// it('should return LnurlPay screen if not from clipboard', async () => {
// const data =
// 'bitcoin:BC1QUXCS7V556UTNUKU93HSZ7LHHFFLWN9NF2UTQ6N?pj=https://ts.dergigi.com/BTC/pj&lightning=LNURL1DP68GURN8GHJ7ARN9EJX2UN8D9NKJTNRDAKJ7SJ5GVH42J2VFE24YNP0WPSHJTMF9ATKWD622CE953JGWV6XXUMRDPXNVCJ8X4G9GF2CHDF';
// mockProcessedSendAddress = {
// value: 'BC1QUXCS7V556UTNUKU93HSZ7LHHFFLWN9NF2UTQ6N',
// lightning:
// 'LNURL1DP68GURN8GHJ7ARN9EJX2UN8D9NKJTNRDAKJ7SJ5GVH42J2VFE24YNP0WPSHJTMF9ATKWD622CE953JGWV6XXUMRDPXNVCJ8X4G9GF2CHDF'
// };
// mockIsValidBitcoinAddress = true;
// mockSupportsOnchainSends = false;

// const result = await handleAnything(data);

// expect(result).toEqual([
// 'LnurlPay',
// {
// lnurlParams: {
// callback:
// 'https://ts.dergigi.com/BTC/UILNURL/pay/i/Wg7JV2ZFHs4cschM6bG5PT',
// commentAllowed: 2000,
// decodedMetadata: [
// [
// 'text/plain',
// 'Paid to dergigi.com (Order ID: V4V-reader)'
// ]
// ],
// domain: 'ts.dergigi.com',
// maxSendable: 612000000000,
// metadata:
// '[["text/plain","Paid to dergigi.com (Order ID: V4V-reader)"]]',
// minSendable: 1000,
// tag: 'payRequest'
// }
// }
// ]);
// });
it('should return LnurlPay screen if not from clipboard', async () => {
const data =
'bitcoin:BC1QUXCS7V556UTNUKU93HSZ7LHHFFLWN9NF2UTQ6N?pj=https://ts.dergigi.com/BTC/pj&lightning=LNURL1DP68GURN8GHJ7ARN9EJX2UN8D9NKJTNRDAKJ7SJ5GVH42J2VFE24YNP0WPSHJTMF9ATKWD622CE953JGWV6XXUMRDPXNVCJ8X4G9GF2CHDF';
mockProcessedSendAddress = {
value: 'BC1QUXCS7V556UTNUKU93HSZ7LHHFFLWN9NF2UTQ6N',
lightning:
'LNURL1DP68GURN8GHJ7ARN9EJX2UN8D9NKJTNRDAKJ7SJ5GVH42J2VFE24YNP0WPSHJTMF9ATKWD622CE953JGWV6XXUMRDPXNVCJ8X4G9GF2CHDF'
};
mockIsValidBitcoinAddress = true;
mockSupportsOnchainSends = false;
mockGetLnurlParams = {
tag: 'payRequest',
domain: 'ts.dergigi.com'
};

const result = await handleAnything(data);

expect(result).toEqual([
'LnurlPay',
{
lnurlParams: mockGetLnurlParams
}
]);
});

it('should return true if from clipboard', async () => {
const data =
Expand Down

0 comments on commit 761bebd

Please sign in to comment.