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

test(pay): add 'pay invoice test' #4008

Merged
merged 7 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion apps/pay/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)

Expand Down
1 change: 1 addition & 0 deletions apps/pay/components/PaymentOutcome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function PaymentOutcome({ paymentRequest, paymentAmount, dispatch }: Props) {
<div className={styles.container}>
<div aria-labelledby="Payment successful">
<Image
data-testid="success-icon"
src="/icons/success-icon.svg"
alt="success icon"
width="104"
Expand Down
48 changes: 48 additions & 0 deletions apps/pay/cypress/e2e/point-of-sale.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { testData } from "../support/test-config"

const username = "test_user_a"
const cashRegisterUrl = `/${username}?amount=0&sats=0&unit=CENT&memo=&display=USD&currency=BTC`
describe("Point of Sale", () => {
Expand Down Expand Up @@ -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")
})
})
})
})
})
})
93 changes: 92 additions & 1 deletion apps/pay/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,95 @@
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

// eslint-disable-next-line @typescript-eslint/no-namespace

declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
flushRedis(): Chainable<void>
loginAndGetToken(phone: string, code: string): Chainable<string>
graphqlOperation(query: string, variables?: Record<string, unknown>, 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)
})
2 changes: 1 addition & 1 deletion apps/pay/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
5 changes: 4 additions & 1 deletion apps/pay/cypress/support/test-config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const testData = {}
export const testData = {
PHONE: "+16505554350",
CODE: "000000",
}
2 changes: 2 additions & 0 deletions dev/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ local_resource(
allow_parallel = True,
resource_deps = [
"api",
"api-ws-server"
],
links = [
link("http://localhost:3002", "pay"),
Expand Down Expand Up @@ -240,6 +241,7 @@ local_resource(
"api",
"pay",
"add-test-users-with-usernames",
"fund-user",
],
)

Expand Down
Loading