mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 22:11:37 +01:00
fix: ๐ callback with query string
This commit is contained in:
parent
e7cba59d36
commit
476db5d755
5 changed files with 140 additions and 1 deletions
31
server/schema/lnurl/__snapshots__/lnurl.test.ts.snap
Normal file
31
server/schema/lnurl/__snapshots__/lnurl.test.ts.snap
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`LNURL Resolvers getBitcoinPrice failure 1`] = `
|
||||
Object {
|
||||
"data": null,
|
||||
"errors": Array [
|
||||
[GraphQLError: ProblemWithdrawingFromLnUrlService],
|
||||
],
|
||||
"extensions": undefined,
|
||||
"http": Object {
|
||||
"headers": Headers {
|
||||
Symbol(map): Object {},
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`LNURL Resolvers getBitcoinPrice success 1`] = `
|
||||
Object {
|
||||
"data": Object {
|
||||
"lnUrlWithdraw": "requestId",
|
||||
},
|
||||
"errors": undefined,
|
||||
"extensions": undefined,
|
||||
"http": Object {
|
||||
"headers": Headers {
|
||||
Symbol(map): Object {},
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
94
server/schema/lnurl/lnurl.test.ts
Normal file
94
server/schema/lnurl/lnurl.test.ts
Normal file
|
@ -0,0 +1,94 @@
|
|||
import testServer from 'server/tests/testServer';
|
||||
import fetchMock from 'jest-fetch-mock';
|
||||
import { GraphQLError } from 'graphql';
|
||||
import { WITHDRAW_LN_URL } from 'src/graphql/mutations/lnUrl';
|
||||
|
||||
jest.mock('ln-service');
|
||||
|
||||
describe('LNURL Resolvers', () => {
|
||||
beforeEach(() => {
|
||||
fetchMock.resetMocks();
|
||||
});
|
||||
describe('getBitcoinPrice', () => {
|
||||
test('success', async () => {
|
||||
fetchMock.mockResponseOnce(JSON.stringify({ status: 'SUCCESS' }));
|
||||
const { mutate } = testServer();
|
||||
|
||||
const res = await mutate({
|
||||
mutation: WITHDRAW_LN_URL,
|
||||
variables: {
|
||||
callback: 'https://domain.com',
|
||||
amount: 1000,
|
||||
k1: 'random',
|
||||
description: 'ln-withdraw',
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.errors).toBe(undefined);
|
||||
|
||||
expect(fetchMock).toBeCalledWith(
|
||||
'https://domain.com?k1=random&pr=boltEncodedRequest',
|
||||
undefined
|
||||
);
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
test('success with callback that has query string', async () => {
|
||||
fetchMock.mockResponseOnce(JSON.stringify({ status: 'SUCCESS' }));
|
||||
const { mutate } = testServer();
|
||||
|
||||
const res = await mutate({
|
||||
mutation: WITHDRAW_LN_URL,
|
||||
variables: {
|
||||
callback: 'https://domain.com?user=123456',
|
||||
amount: 1000,
|
||||
k1: 'random',
|
||||
description: 'ln-withdraw',
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.errors).toBe(undefined);
|
||||
|
||||
expect(fetchMock).toBeCalledWith(
|
||||
'https://domain.com?user=123456&k1=random&pr=boltEncodedRequest',
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('success but not able to withdraw', async () => {
|
||||
fetchMock.mockResponseOnce(JSON.stringify({ status: 'ERROR' }));
|
||||
const { mutate } = testServer();
|
||||
|
||||
const res = await mutate({
|
||||
mutation: WITHDRAW_LN_URL,
|
||||
variables: {
|
||||
callback: 'https://domain.com',
|
||||
amount: 1000,
|
||||
k1: 'random',
|
||||
description: 'ln-withdraw',
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.errors).toStrictEqual([
|
||||
new GraphQLError('ProblemWithdrawingFromLnUrlService'),
|
||||
]);
|
||||
});
|
||||
test('failure', async () => {
|
||||
fetchMock.mockRejectOnce(new Error('Error'));
|
||||
const { mutate } = testServer();
|
||||
|
||||
const res = await mutate({
|
||||
mutation: WITHDRAW_LN_URL,
|
||||
variables: {
|
||||
callback: 'domain.com',
|
||||
amount: 1000,
|
||||
k1: 'random',
|
||||
description: 'ln-withdraw',
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.errors).toStrictEqual([
|
||||
new GraphQLError('ProblemWithdrawingFromLnUrlService'),
|
||||
]);
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -213,7 +213,10 @@ export const lnUrlResolvers = {
|
|||
createInvoice({ lnd, tokens: amount, description })
|
||||
);
|
||||
|
||||
const finalUrl = `${callback}?k1=${k1}&pr=${info.request}`;
|
||||
// If the callback url already has an initial query '?' identifier we don't need to add it again.
|
||||
const initialIdentifier = callback.indexOf('?') != -1 ? '&' : '?';
|
||||
|
||||
const finalUrl = `${callback}${initialIdentifier}k1=${k1}&pr=${info.request}`;
|
||||
|
||||
try {
|
||||
const response = await fetchWithProxy(finalUrl);
|
||||
|
|
|
@ -103,3 +103,7 @@ export const verifyMessage = jest
|
|||
export const getPublicKey = jest
|
||||
.fn()
|
||||
.mockReturnValue(Promise.resolve(res.getPublicKeyResponse));
|
||||
|
||||
export const createInvoice = jest
|
||||
.fn()
|
||||
.mockReturnValue(Promise.resolve(res.createInvoiceResponse));
|
||||
|
|
|
@ -763,3 +763,10 @@ export const verifyMessageResponse = {
|
|||
export const getPublicKeyResponse = {
|
||||
public_key: 'public_key',
|
||||
};
|
||||
|
||||
export const createInvoiceResponse = {
|
||||
request: 'boltEncodedRequest',
|
||||
created_at: '',
|
||||
id: 'requestId',
|
||||
secret: 'secretString',
|
||||
};
|
||||
|
|
Loadingโฆ
Add table
Reference in a new issue