aboutsummaryrefslogtreecommitdiffstats
path: root/test/e2e/receive-lightning-redirect.spec.ts
blob: d6670dca7a0bc4f294b59deb03c2c0dde42e6b9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expect, test } from "@playwright/test";
import { apiBaseUrl, bobUsername, bobPassword, login, lightningPay } from "./helpers";

test("redirects from /receive to /paid when lightning address payment arrives", async ({
  page,
}) => {
  test.setTimeout(90_000);

  // --- Bob: log in and navigate to receive page ---
  await login(page, bobUsername, bobPassword);
  await page.goto(`/${bobUsername}/receive`);
  await page.waitForLoadState("networkidle");
  console.log(`[e2e] Bob on receive page: ${page.url()}`);

  // Ensure we're on the receive page (not redirected to an invoice)
  expect(page.url()).toContain(`/${bobUsername}/receive`);

  // Small delay to ensure websocket is connected
  await page.waitForTimeout(1000);

  // --- External: create and pay LNURL invoice ---
  // Step 1: Fetch LNURL pay request
  const lnurlRes = await page.request.get(`${apiBaseUrl}/lnurlp/${bobUsername}`);
  const lnurlData = await lnurlRes.json();
  expect(lnurlData.callback).toBeTruthy();
  console.log(`[e2e] LNURL callback: ${lnurlData.callback}`);

  // Step 2: Call callback with 100 sat (100000 msat) to get bolt11
  const callbackUrl = lnurlData.callback.replace("https://dev.coinos.io/api", apiBaseUrl);
  const callbackRes = await page.request.get(`${callbackUrl}?amount=100000`);
  const callbackData = await callbackRes.json();
  const bolt11 = callbackData.pr;
  expect(bolt11).toBeTruthy();
  console.log(`[e2e] Got bolt11: ${bolt11.substring(0, 40)}...`);

  // Step 3: Pay from external lightning node
  console.log("[e2e] Paying from external lightning node (clb)...");
  const payResult = lightningPay(bolt11);
  console.log(`[e2e] Lightning pay result: ${payResult.substring(0, 100)}`);

  // --- Bob: should be redirected to /paid ---
  await page.waitForURL(/\/invoice\/[^/]+\/paid/, { timeout: 15_000 });
  console.log(`[e2e] Bob redirected to: ${page.url()}`);

  // Verify success UI is shown
  const heading = await page.locator("h1").first().innerText({ timeout: 5_000 });
  expect(
    heading.toLowerCase().includes("payment") || heading.toLowerCase().includes("success"),
    `Expected payment success/detected text, got: ${heading}`,
  ).toBeTruthy();

  if (process.env.E2E_PAUSE_AT_END === "true") await page.pause();
});