Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lnurl test #2006

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
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
Loading