diff --git a/apps/pay/BUCK b/apps/pay/BUCK index 9aee47c716..692782e415 100644 --- a/apps/pay/BUCK +++ b/apps/pay/BUCK @@ -77,7 +77,10 @@ next_build( name = "build-ci", srcs = [":src"], build_env = { - "NEXT_PUBLIC_CORE_GQL_URL": "http://localhost:4455/graphql" + "CORE_GQL_URL_INTRANET": "http://localhost:4455/graphql", + "NEXT_PUBLIC_CORE_GQL_URL": "http://localhost:4455/graphql", + "NEXT_PUBLIC_CORE_GQL_WEB_SOCKET_URL": "ws://localhost:4455/graphqlws", + "NEXT_PUBLIC_PAY_DOMAIN": "localhost:3002", } ) diff --git a/apps/pay/components/PaymentOutcome/index.tsx b/apps/pay/components/PaymentOutcome/index.tsx index 9c1fda2b8d..f268ff7a7a 100644 --- a/apps/pay/components/PaymentOutcome/index.tsx +++ b/apps/pay/components/PaymentOutcome/index.tsx @@ -95,6 +95,7 @@ function PaymentOutcome({ paymentRequest, paymentAmount, dispatch }: Props) {
success icon { @@ -54,4 +56,50 @@ describe("Point of Sale", () => { cy.get("[data-testid=qrcode-container]").as("qrcodeContainer") cy.get("@qrcodeContainer").find("canvas").should("exist") }) + + it("should create and pay an invoice", () => { + cy.visit(cashRegisterUrl) + cy.get("button[data-testid=digit-1-btn]").click() + cy.get("button[data-testid=digit-0-btn]").click() + cy.get("button[data-testid=pay-btn]").click() + + cy.get("[data-testid=copy-btn]").should("exist") + cy.get("[data-testid=share-lbl]").should("exist") + cy.get("[data-testid=qrcode-container]").should("exist") + cy.get("[data-testid=qrcode-container]").as("qrcodeContainer") + cy.get("@qrcodeContainer").find("canvas").should("exist") + cy.get("[data-testid=copy-btn]").should("exist").click() + + cy.window() + .then((win) => { + win.focus() + return win.navigator.clipboard.readText() + }) + .then((text) => { + const paymentRequest = text + cy.log("Payment Request:", paymentRequest) + + cy.loginAndGetToken(testData.PHONE, testData.CODE).then((token) => { + const authToken = token + cy.log("authToken", authToken) + + cy.fetchMe(authToken).then((response) => { + const walletId = response.body.data.me.defaultAccount.defaultWalletId + cy.log("Wallet ID:", walletId) + + cy.sendInvoicePayment(paymentRequest, walletId, authToken) + .then((paymentResponse) => { + expect(paymentResponse.body.data.lnInvoicePaymentSend.status).to.equal( + "SUCCESS", + ) + }) + .then(() => { + cy.wait(3000) + cy.get("[data-testid=success-icon]").should("exist") + cy.get("[data-testid=success-icon]").should("be.visible") + }) + }) + }) + }) + }) }) diff --git a/apps/pay/cypress/support/commands.ts b/apps/pay/cypress/support/commands.ts index 95857aea4c..26dc2f1aca 100644 --- a/apps/pay/cypress/support/commands.ts +++ b/apps/pay/cypress/support/commands.ts @@ -34,4 +34,95 @@ // visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable // } // } -// } + +// eslint-disable-next-line @typescript-eslint/no-namespace + +declare namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + flushRedis(): Chainable + loginAndGetToken(phone: string, code: string): Chainable + graphqlOperation(query: string, variables?: Record, token: string) + fetchMe(token: string) + sendInvoicePayment(paymentRequest: string, walletId: string, token: string) + } +} + +Cypress.Commands.add("flushRedis", () => { + const command = `docker exec galoy-dev-redis-1 redis-cli FLUSHALL` + cy.exec(command).then((result) => { + if (result.code === 0) { + cy.log("Redis FLUSHALL executed successfully") + } else { + throw new Error("Failed to execute FLUSHALL on Redis") + } + }) +}) + +Cypress.Commands.add("loginAndGetToken", (phone, code) => { + cy.flushRedis() + cy.request({ + method: "POST", + url: "http://localhost:4455/auth/phone/login", + body: { + phone, + code, + }, + }).then((response) => { + expect(response.body).to.have.property("authToken") + return response.body.authToken + }) +}) + +Cypress.Commands.add("graphqlOperation", (query, variables = {}, token) => { + return cy.request({ + method: "POST", + url: "http://localhost:4455/graphql", + body: { + query, + variables, + }, + headers: { + Authorization: `Bearer ${token}`, + }, + }) +}) + +Cypress.Commands.add("fetchMe", (token) => { + const query = ` + query Me { + me { + id + defaultAccount { + defaultWalletId + displayCurrency + id + level + } + } + } + ` + return cy.graphqlOperation(query, {}, token) +}) + +Cypress.Commands.add("sendInvoicePayment", (paymentRequest, walletId, token) => { + const mutation = ` + mutation LnInvoicePaymentSend($input: LnInvoicePaymentInput!) { + lnInvoicePaymentSend(input: $input) { + errors { + code + message + path + } + status + } + } + ` + const variables = { + input: { + paymentRequest, + walletId, + }, + } + return cy.graphqlOperation(mutation, variables, token) +}) diff --git a/apps/pay/cypress/support/e2e.ts b/apps/pay/cypress/support/e2e.ts index b9cff7d3c9..fdd4334330 100644 --- a/apps/pay/cypress/support/e2e.ts +++ b/apps/pay/cypress/support/e2e.ts @@ -15,7 +15,7 @@ // Import commands.js using ES2015 syntax: // eslint-disable-next-line import/no-unassigned-import -// import "./commands" +import "./commands" // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/apps/pay/cypress/support/test-config.ts b/apps/pay/cypress/support/test-config.ts index b5d08344e8..8f1833b0c9 100644 --- a/apps/pay/cypress/support/test-config.ts +++ b/apps/pay/cypress/support/test-config.ts @@ -1 +1,4 @@ -export const testData = {} +export const testData = { + PHONE: "+16505554350", + CODE: "000000", +} diff --git a/dev/Tiltfile b/dev/Tiltfile index 15ed4311cd..11f648c160 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -112,6 +112,7 @@ local_resource( allow_parallel = True, resource_deps = [ "api", + "api-ws-server" ], links = [ link("http://localhost:3002", "pay"), @@ -240,6 +241,7 @@ local_resource( "api", "pay", "add-test-users-with-usernames", + "fund-user", ], )