Skip to content

Commit

Permalink
fix: cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Jan 15, 2025
1 parent f5ee02c commit 4cc0717
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
6 changes: 3 additions & 3 deletions apps/admin-panel/cypress/e2e/credit-facilities.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe("credit facility", () => {

const testEmail = `test-${Date.now()}@example.com`
const testTelegramId = `user${Date.now()}`
cy.createCustomer(testEmail, testTelegramId).then((id) => {
customerId = id
cy.log(`Created customer with ID: ${id}`)
cy.createCustomer(testEmail, testTelegramId).then((customer) => {
customerId = customer.customerId
cy.log(`Created customer with ID: ${customerId}`)
})
})

Expand Down
20 changes: 11 additions & 9 deletions apps/admin-panel/cypress/e2e/governance.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ describe("Governance Test", () => {
let committeeName: string
let committeeId: string
let customerId: string
let depositAccountId: string

before(() => {
const testEmail = `test-${Date.now()}@example.com`
const testTelegramId = `user${Date.now()}`
cy.createCustomer(testEmail, testTelegramId).then((id) => {
customerId = id
cy.log(`Created customer with ID: ${id}`)
cy.createCustomer(testEmail, testTelegramId).then((customer) => {
customerId = customer.customerId
depositAccountId = customer.depositAccount.depositAccountId
cy.log(`Created customer with ID: ${customerId}`)
})
})

Expand Down Expand Up @@ -100,8 +102,8 @@ describe("Governance Test", () => {

it("Pending actions should be visible in list", () => {
const amount = 1000
cy.createDeposit(amount, customerId).then(() => {
cy.initiateWithdrawal(amount, customerId).then(() => {
cy.createDeposit(amount, depositAccountId).then(() => {
cy.initiateWithdrawal(amount, depositAccountId).then(() => {
cy.visit(`/actions`)
cy.get('[data-testid="table-row-0"] > :nth-child(4) > a > .gap-2').should(
"be.visible",
Expand All @@ -119,8 +121,8 @@ describe("Governance Test", () => {

it("Committee member should be able to approve a withdraw", () => {
const amount = 1000
cy.createDeposit(amount, customerId).then(() => {
cy.initiateWithdrawal(amount, customerId).then((withdrawalId) => {
cy.createDeposit(amount, depositAccountId).then(() => {
cy.initiateWithdrawal(amount, depositAccountId).then((withdrawalId) => {
cy.visit(`/withdrawals/${withdrawalId}`)
cy.get("[data-testid=withdrawal-status-badge]").should("be.visible")
cy.takeScreenshot("18_step-visit-withdrawal-details")
Expand Down Expand Up @@ -150,8 +152,8 @@ describe("Governance Test", () => {

it("Committee member should be able to deny a withdraw", () => {
const amount = 1000
cy.createDeposit(amount, customerId).then(() => {
cy.initiateWithdrawal(amount, customerId).then((withdrawalId) => {
cy.createDeposit(amount, depositAccountId).then(() => {
cy.initiateWithdrawal(amount, depositAccountId).then((withdrawalId) => {
cy.visit(`/withdrawals/${withdrawalId}`)
cy.get("[data-testid=withdrawal-status-badge]").should("be.visible")
cy.takeScreenshot("21_step-visit-withdrawal-for-denial")
Expand Down
18 changes: 11 additions & 7 deletions apps/admin-panel/cypress/e2e/transactions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { faker } from "@faker-js/faker"

describe("Transactions Deposit and Withdraw", () => {
let customerId: string
let depositAccountId: string
const depositAmount = faker.number.int({ min: 1000, max: 5000 })
const withdrawAmount = faker.number.int({ min: 1000, max: depositAmount })

before(() => {
const testEmail = `test-${Date.now()}@example.com`
const testTelegramId = `user${Date.now()}`
cy.createCustomer(testEmail, testTelegramId).then((id) => {
customerId = id
cy.log(`Created customer with ID: ${id}`)
cy.createCustomer(testEmail, testTelegramId).then((customer) => {
customerId = customer.customerId
depositAccountId = customer.depositAccount.depositAccountId
cy.log(`Created customer with ID: ${customerId}`)
})
})

Expand Down Expand Up @@ -91,8 +93,10 @@ describe("Transactions Deposit and Withdraw", () => {
})

it("should show newly created Withdraw in list page", () => {
cy.createDeposit(depositAmount, customerId).then(() => {
cy.initiateWithdrawal(withdrawAmount, customerId).then((withdrawalId) => {
console.log("should show newly created Withdraw in list page")

cy.createDeposit(depositAmount, depositAccountId).then(() => {
cy.initiateWithdrawal(withdrawAmount, depositAccountId).then((withdrawalId) => {
cy.visit(`/withdrawals/${withdrawalId}`)
cy.wait(1000)
cy.get("[data-testid=withdrawal-status-badge]").then((badge) => {
Expand Down Expand Up @@ -123,8 +127,8 @@ describe("Transactions Deposit and Withdraw", () => {
})

it("should approve Withdraw", () => {
cy.createDeposit(depositAmount, customerId).then(() => {
cy.initiateWithdrawal(withdrawAmount, customerId).then((withdrawalId) => {
cy.createDeposit(depositAmount, depositAccountId).then(() => {
cy.initiateWithdrawal(withdrawAmount, depositAccountId).then((withdrawalId) => {
cy.visit(`/withdrawals/${withdrawalId}`)
cy.wait(1000)
cy.get("[data-testid=withdrawal-status-badge]")
Expand Down
35 changes: 23 additions & 12 deletions apps/admin-panel/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import "cypress-file-upload"

import { TermsTemplateCreateInput } from "@/lib/graphql/generated"

type Customer = {
customerId: string
depositAccount: {
id: string
depositAccountId: string
}
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
takeScreenshot(filename: string): Chainable<null>
createCustomer(email: string, telegramId: string): Chainable<string>
createCustomer(email: string, telegramId: string): Chainable<Customer>
createTermsTemplate(input: TermsTemplateCreateInput): Chainable<string>
graphqlRequest<T>(query: string, variables?: Record<string, unknown>): Chainable<T>
getIdFromUrl(pathSegment: string): Chainable<string>
createDeposit(amount: number, customerId: string): Chainable<string>
initiateWithdrawal(amount: number, customerId: string): Chainable<string>
createDeposit(amount: number, depositAccountId: string): Chainable<string>
initiateWithdrawal(amount: number, depositAccountId: string): Chainable<string>
}
}
}
Expand Down Expand Up @@ -52,20 +60,23 @@ Cypress.Commands.add("takeScreenshot", (filename): Cypress.Chainable<null> => {
interface CustomerResponse {
data: {
customerCreate: {
customer: {
customerId: string
}
customer: Customer
}
}
}

Cypress.Commands.add(
"createCustomer",
(email: string, telegramId: string): Cypress.Chainable<string> => {
(email: string, telegramId: string): Cypress.Chainable<Customer> => {
const mutation = `
mutation CustomerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
customer {
customerId
depositAccount {
id
depositAccountId
}
}
}
}
Expand All @@ -74,7 +85,7 @@ Cypress.Commands.add(
.graphqlRequest<CustomerResponse>(mutation, {
input: { email, telegramId },
})
.then((response) => response.data.customerCreate.customer.customerId)
.then((response) => response.data.customerCreate.customer)
},
)

Expand Down Expand Up @@ -149,7 +160,7 @@ interface WithdrawalInitiateResponse {

Cypress.Commands.add(
"createDeposit",
(amount: number, customerId: string): Cypress.Chainable<string> => {
(amount: number, depositAccountId: string): Cypress.Chainable<string> => {
const mutation = `
mutation CreateDeposit($input: DepositRecordInput!) {
depositRecord(input: $input) {
Expand All @@ -161,15 +172,15 @@ Cypress.Commands.add(
`
return cy
.graphqlRequest<DepositResponse>(mutation, {
input: { amount, customerId },
input: { amount, depositAccountId },
})
.then((response) => response.data.depositRecord.deposit.depositId)
},
)

Cypress.Commands.add(
"initiateWithdrawal",
(amount: number, customerId: string): Cypress.Chainable<string> => {
(amount: number, depositAccountId: string): Cypress.Chainable<string> => {
const mutation = `
mutation WithdrawalInitiate($input: WithdrawalInitiateInput!) {
withdrawalInitiate(input: $input) {
Expand All @@ -181,7 +192,7 @@ Cypress.Commands.add(
`
return cy
.graphqlRequest<WithdrawalInitiateResponse>(mutation, {
input: { amount, customerId },
input: { amount, depositAccountId },
})
.then((response) => response.data.withdrawalInitiate.withdrawal.withdrawalId)
},
Expand Down

0 comments on commit 4cc0717

Please sign in to comment.