From e796b0b314e07b6cd03863ae7cc136f6fc9942e9 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Mon, 24 Jun 2024 19:58:02 -0400 Subject: [PATCH] Really disable everything but bankaccounts --- src/__tests__/bankaccounts.test.ts | 2 +- src/__tests__/comments.test.ts | 47 ++- src/__tests__/contacts.test.ts | 78 ++--- src/__tests__/likes.test.ts | 43 +-- src/__tests__/notifications.test.ts | 205 +++++------ src/__tests__/transactions.test.ts | 525 ++++++++++++---------------- src/__tests__/users.test.ts | 81 ++--- 7 files changed, 434 insertions(+), 547 deletions(-) diff --git a/src/__tests__/bankaccounts.test.ts b/src/__tests__/bankaccounts.test.ts index f41d8c925..33ddc0f4b 100644 --- a/src/__tests__/bankaccounts.test.ts +++ b/src/__tests__/bankaccounts.test.ts @@ -10,7 +10,7 @@ import { } from "../../backend/database"; import { User } from "../../src/models/user"; import { BankAccount } from "../../src/models/bankaccount"; -describe("BankAccounts", () => { +describe.only("BankAccounts", () => { beforeEach(() => { seedDatabase(); }); diff --git a/src/__tests__/comments.test.ts b/src/__tests__/comments.test.ts index 3a0c4e445..c37c668dc 100644 --- a/src/__tests__/comments.test.ts +++ b/src/__tests__/comments.test.ts @@ -10,31 +10,24 @@ import { import { User, Transaction } from "../../src/models"; -describe.skip("Comments", () => { - beforeEach(() => { - seedDatabase(); - }); - - it("should comment a transaction for a contact", () => { - const user: User = getAllUsers()[0]; - const transactions: Transaction[] = getTransactionsForUserContacts(user.id); - - const content = "This is my comment content"; - const comment = createComment(user.id, transactions[0].id, content); - - expect(comment.transactionId).toBe(transactions[0].id); - expect(comment.content).toBe(content); - }); - - it("should get a list of comments for a transaction", () => { - const user: User = getAllUsers()[0]; - const transactions: Transaction[] = getTransactionsByUserId(user.id); - const transaction = transactions[0]; - - createComment(user.id, transaction.id, "This is my comment"); - - const comments = getCommentsByTransactionId(transaction.id); - - expect(comments[0].transactionId).toBe(transaction.id); - }); +describe("Comments", () => { + // beforeEach(() => { + // seedDatabase(); + // }); + // it("should comment a transaction for a contact", () => { + // const user: User = getAllUsers()[0]; + // const transactions: Transaction[] = getTransactionsForUserContacts(user.id); + // const content = "This is my comment content"; + // const comment = createComment(user.id, transactions[0].id, content); + // expect(comment.transactionId).toBe(transactions[0].id); + // expect(comment.content).toBe(content); + // }); + // it("should get a list of comments for a transaction", () => { + // const user: User = getAllUsers()[0]; + // const transactions: Transaction[] = getTransactionsByUserId(user.id); + // const transaction = transactions[0]; + // createComment(user.id, transaction.id, "This is my comment"); + // const comments = getCommentsByTransactionId(transaction.id); + // expect(comments[0].transactionId).toBe(transaction.id); + // }); }); diff --git a/src/__tests__/contacts.test.ts b/src/__tests__/contacts.test.ts index c8e75c5d9..6ca0d0acb 100644 --- a/src/__tests__/contacts.test.ts +++ b/src/__tests__/contacts.test.ts @@ -11,49 +11,37 @@ import { } from "../../backend/database"; import { User } from "../../src/models/user"; import { totalContacts, contactsPerUser } from "../../scripts/seedDataUtils"; -describe.skip("Contacts", () => { - beforeEach(() => { - seedDatabase(); - }); - - it("should retrieve a list of contacts", () => { - expect(getAllContacts().length).toEqual(totalContacts); - }); - - it("should retrieve a list of contacts for a username", () => { - const userToLookup: User = getAllUsers()[0]; - - const result = getContactsByUsername(userToLookup.username); - expect(result.length).toBeGreaterThanOrEqual(contactsPerUser); - expect(result[0].userId).toBe(userToLookup.id); - }); - - it("should retrieve a list of contacts for a userId", () => { - const userToLookup: User = getAllUsers()[0]; - - const result = getContactsByUserId(userToLookup.id); - expect(result.length).toBeGreaterThanOrEqual(3); - expect(result[0].userId).toBe(userToLookup.id); - }); - - it("should create a contact for user", () => { - const user: User = getRandomUser(); - const contactToBe: User = getRandomUser(); - - const result = createContactForUser(user.id, contactToBe.id); - expect(result.userId).toBe(user.id); - }); - - it("should delete a contact", () => { - const userToLookup: User = getRandomUser(); - - const contacts = getContactsByUsername(userToLookup.username); - - const contactId = contacts[0].id; - - removeContactById(contactId); - - const updatedContacts = getContactsByUsername(userToLookup.username); - expect(updatedContacts.length).toBeLessThan(contacts.length); - }); +describe("Contacts", () => { + // beforeEach(() => { + // seedDatabase(); + // }); + // it("should retrieve a list of contacts", () => { + // expect(getAllContacts().length).toEqual(totalContacts); + // }); + // it("should retrieve a list of contacts for a username", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result = getContactsByUsername(userToLookup.username); + // expect(result.length).toBeGreaterThanOrEqual(contactsPerUser); + // expect(result[0].userId).toBe(userToLookup.id); + // }); + // it("should retrieve a list of contacts for a userId", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result = getContactsByUserId(userToLookup.id); + // expect(result.length).toBeGreaterThanOrEqual(3); + // expect(result[0].userId).toBe(userToLookup.id); + // }); + // it("should create a contact for user", () => { + // const user: User = getRandomUser(); + // const contactToBe: User = getRandomUser(); + // const result = createContactForUser(user.id, contactToBe.id); + // expect(result.userId).toBe(user.id); + // }); + // it("should delete a contact", () => { + // const userToLookup: User = getRandomUser(); + // const contacts = getContactsByUsername(userToLookup.username); + // const contactId = contacts[0].id; + // removeContactById(contactId); + // const updatedContacts = getContactsByUsername(userToLookup.username); + // expect(updatedContacts.length).toBeLessThan(contacts.length); + // }); }); diff --git a/src/__tests__/likes.test.ts b/src/__tests__/likes.test.ts index c70ad0115..aaafd309f 100644 --- a/src/__tests__/likes.test.ts +++ b/src/__tests__/likes.test.ts @@ -10,29 +10,22 @@ import { import { User, Transaction } from "../../src/models"; -describe.skip("Transactions", () => { - beforeEach(() => { - seedDatabase(); - }); - - it("should like a transaction for a contact", () => { - const user: User = getAllUsers()[0]; - const transactions: Transaction[] = getTransactionsForUserContacts(user.id); - - const like = createLike(user.id, transactions[0].id); - - expect(like.transactionId).toBe(transactions[0].id); - }); - - it("should get a list of likes for a transaction", () => { - const user: User = getAllUsers()[0]; - const transactions: Transaction[] = getTransactionsByUserId(user.id); - const transaction = transactions[0]; - - createLike(user.id, transaction.id); - - const likes = getLikesByTransactionId(transaction.id); - - expect(likes[0].transactionId).toBe(transaction.id); - }); +describe("Transactions", () => { + // beforeEach(() => { + // seedDatabase(); + // }); + // it("should like a transaction for a contact", () => { + // const user: User = getAllUsers()[0]; + // const transactions: Transaction[] = getTransactionsForUserContacts(user.id); + // const like = createLike(user.id, transactions[0].id); + // expect(like.transactionId).toBe(transactions[0].id); + // }); + // it("should get a list of likes for a transaction", () => { + // const user: User = getAllUsers()[0]; + // const transactions: Transaction[] = getTransactionsByUserId(user.id); + // const transaction = transactions[0]; + // createLike(user.id, transaction.id); + // const likes = getLikesByTransactionId(transaction.id); + // expect(likes[0].transactionId).toBe(transaction.id); + // }); }); diff --git a/src/__tests__/notifications.test.ts b/src/__tests__/notifications.test.ts index 54a5741f7..ee53da666 100644 --- a/src/__tests__/notifications.test.ts +++ b/src/__tests__/notifications.test.ts @@ -29,114 +29,99 @@ import { NotificationType, } from "../../src/models"; -describe.skip("Notifications", () => { - let user: User; - beforeEach(() => { - seedDatabase(); - user = getAllUsers()[0]; - }); - - describe("create notifications", () => { - let transactions: Transaction[]; - let transaction: Transaction; - let paymentNotification: PaymentNotification; - let like: Like; - let likeNotification: LikeNotification; - let comment: Comment; - let commentNotification: CommentNotification; - beforeEach(() => { - user = getAllUsers()[0]; - transactions = getTransactionsForUserContacts(user.id); - transaction = transactions[0]; - paymentNotification = createPaymentNotification( - user.id, - transaction.id, - PaymentNotificationStatus.received - ); - like = createLike(user.id, transaction.id); - likeNotification = createLikeNotification(user.id, transaction.id, like.id); - comment = createComment(user.id, transaction.id, "This is my comment"); - - commentNotification = createCommentNotification(user.id, transaction.id, comment.id); - }); - - it("should create a payment notification for a transaction", () => { - expect(paymentNotification.transactionId).toBe(transaction.id); - expect(paymentNotification.status).toBe(PaymentNotificationStatus.received); - }); - - it("should create a like notification for a transaction", () => { - expect(likeNotification.transactionId).toBe(transaction.id); - expect(likeNotification.likeId).toBe(like.id); - }); - - it("should create a comment notification for a transaction", () => { - expect(commentNotification.transactionId).toBe(transaction.id); - expect(commentNotification.commentId).toBe(comment.id); - }); - - it("should format comment notification for api", () => { - const apiNotification = formatNotificationForApiResponse(commentNotification); - expect(apiNotification.userFullName).toBeDefined(); - }); - - it("should create notifications for a transaction", () => { - const notificationsPayload = [ - { - type: NotificationsType.payment, - transactionId: transaction.id, - status: PaymentNotificationStatus.received, - }, - { - type: NotificationsType.like, - transactionId: transaction.id, - likeId: like.id, - }, - { - type: NotificationsType.comment, - transactionId: transaction.id, - commentId: comment.id, - }, - ]; - - const notifications = createNotifications(user.id, notificationsPayload); - - expect(notifications[0]!.transactionId).toBe(transaction.id); - // @ts-ignore - expect(notifications[1]!.likeId).toBe(like.id); - // @ts-ignore - expect(notifications[2]!.commentId).toBe(comment.id); - }); - }); - - it("should get a list of notifications for a user", () => { - const transactions: Transaction[] = getTransactionsByUserId(user.id); - const transaction = transactions[0]; - - // create comment and like and notifications for transaction - const comment = createComment(user.id, transaction.id, "This is my notification content"); - createCommentNotification(user.id, transaction.id, comment.id); - const like = createLike(user.id, transaction.id); - createLikeNotification(user.id, transaction.id, like.id); - - const notifications = getNotificationsByUserId(user.id); - - expect(notifications.length).toBeGreaterThan(1); - expect(notifications[notifications.length - 1]).toMatchObject({ - transactionId: transaction.id, - }); - }); - - it("should update a notification", () => { - const notifications = getNotificationsByUserId(user.id); - const edits: Partial = { - isRead: true, - }; - // @ts-ignore - updateNotificationById(user.id, notifications[0].id, edits); - - // @ts-ignore - const updatedNotification = getNotificationById(notifications[0].id); - expect(updatedNotification.isRead).toBe(true); - }); +describe("Notifications", () => { + // let user: User; + // beforeEach(() => { + // seedDatabase(); + // user = getAllUsers()[0]; + // }); + // describe("create notifications", () => { + // let transactions: Transaction[]; + // let transaction: Transaction; + // let paymentNotification: PaymentNotification; + // let like: Like; + // let likeNotification: LikeNotification; + // let comment: Comment; + // let commentNotification: CommentNotification; + // beforeEach(() => { + // user = getAllUsers()[0]; + // transactions = getTransactionsForUserContacts(user.id); + // transaction = transactions[0]; + // paymentNotification = createPaymentNotification( + // user.id, + // transaction.id, + // PaymentNotificationStatus.received + // ); + // like = createLike(user.id, transaction.id); + // likeNotification = createLikeNotification(user.id, transaction.id, like.id); + // comment = createComment(user.id, transaction.id, "This is my comment"); + // commentNotification = createCommentNotification(user.id, transaction.id, comment.id); + // }); + // it("should create a payment notification for a transaction", () => { + // expect(paymentNotification.transactionId).toBe(transaction.id); + // expect(paymentNotification.status).toBe(PaymentNotificationStatus.received); + // }); + // it("should create a like notification for a transaction", () => { + // expect(likeNotification.transactionId).toBe(transaction.id); + // expect(likeNotification.likeId).toBe(like.id); + // }); + // it("should create a comment notification for a transaction", () => { + // expect(commentNotification.transactionId).toBe(transaction.id); + // expect(commentNotification.commentId).toBe(comment.id); + // }); + // it("should format comment notification for api", () => { + // const apiNotification = formatNotificationForApiResponse(commentNotification); + // expect(apiNotification.userFullName).toBeDefined(); + // }); + // it("should create notifications for a transaction", () => { + // const notificationsPayload = [ + // { + // type: NotificationsType.payment, + // transactionId: transaction.id, + // status: PaymentNotificationStatus.received, + // }, + // { + // type: NotificationsType.like, + // transactionId: transaction.id, + // likeId: like.id, + // }, + // { + // type: NotificationsType.comment, + // transactionId: transaction.id, + // commentId: comment.id, + // }, + // ]; + // const notifications = createNotifications(user.id, notificationsPayload); + // expect(notifications[0]!.transactionId).toBe(transaction.id); + // // @ts-ignore + // expect(notifications[1]!.likeId).toBe(like.id); + // // @ts-ignore + // expect(notifications[2]!.commentId).toBe(comment.id); + // }); + // }); + // it("should get a list of notifications for a user", () => { + // const transactions: Transaction[] = getTransactionsByUserId(user.id); + // const transaction = transactions[0]; + // // create comment and like and notifications for transaction + // const comment = createComment(user.id, transaction.id, "This is my notification content"); + // createCommentNotification(user.id, transaction.id, comment.id); + // const like = createLike(user.id, transaction.id); + // createLikeNotification(user.id, transaction.id, like.id); + // const notifications = getNotificationsByUserId(user.id); + // expect(notifications.length).toBeGreaterThan(1); + // expect(notifications[notifications.length - 1]).toMatchObject({ + // transactionId: transaction.id, + // }); + // }); + // it("should update a notification", () => { + // const notifications = getNotificationsByUserId(user.id); + // const edits: Partial = { + // isRead: true, + // }; + // // @ts-ignore + // updateNotificationById(user.id, notifications[0].id, edits); + // // @ts-ignore + // const updatedNotification = getNotificationById(notifications[0].id); + // expect(updatedNotification.isRead).toBe(true); + // }); }); diff --git a/src/__tests__/transactions.test.ts b/src/__tests__/transactions.test.ts index bd4682cb6..f6afb8fe6 100644 --- a/src/__tests__/transactions.test.ts +++ b/src/__tests__/transactions.test.ts @@ -29,296 +29,237 @@ import { import { getFakeAmount } from "../../src/utils/transactionUtils"; import { totalTransactions, transactionsPerUser } from "../../scripts/seedDataUtils"; -describe.skip("Transactions", () => { - beforeEach(() => { - seedDatabase(); - }); - - it("should retrieve a list of all transactions", () => { - expect(getAllTransactions().length).toBe(totalTransactions); - }); - - it("should retrieve a list of all public transactions", () => { - expect(getAllPublicTransactions().length).toBeGreaterThan(transactionsPerUser); - expect(getAllPublicTransactions().length).toBeLessThan(totalTransactions); - }); - - it("should retrieve a list of transactions for a user (user is receiver)", () => { - const userToLookup: User = getAllUsers()[0]; - - const result: Transaction[] = getTransactionsForUserByObj(userToLookup.id, { - status: "complete", - }); - expect(result[0].receiverId).toBe(userToLookup.id); - }); - - it("should retrieve a list of transactions for a user (user is sender)", () => { - const userToLookup: User = getAllUsers()[0]; - - const result: Transaction[] = getTransactionsForUserByObj(userToLookup.id, {}); - expect(result.pop()!.senderId).toBe(userToLookup.id); - }); - - it("should retrieve a list of transactions for a users contacts", () => { - const userToLookup: User = getAllUsers()[0]; - const result: Transaction[] = getTransactionsForUserContacts(userToLookup.id); - - expect(result.length).toBeGreaterThan(transactionsPerUser); - expect(result.length).toBeLessThan(totalTransactions); - }); - - it("should retrieve a list of transactions for a users contacts - between date range", () => { - const userToLookup: User = getAllUsers()[0]; - const result: Transaction[] = getTransactionsForUserContacts(userToLookup.id, { - dateRangeStart: new Date("Mar 09 2023"), - dateRangeEnd: new Date("Mar 09 2024"), - }); - expect(result.length).toBeGreaterThan(1); - }); - - it("should retrieve a list of public transactions, default sort", () => { - const user: User = getAllUsers()[0]; - const contactsTransactions: Transaction[] = getTransactionsForUserContacts(user.id); - expect(contactsTransactions.length).toBeGreaterThan(1); - expect(contactsTransactions.length).toBeLessThan(totalTransactions); - - const response = getPublicTransactionsDefaultSort(user.id); - - expect(response.contactsTransactions.length).toBeGreaterThan(1); - expect(response.contactsTransactions.length).toBeLessThan(totalTransactions); - expect(response.publicTransactions.length).toBeGreaterThan(1); - expect(response.publicTransactions.length).toBeLessThan(totalTransactions); - - const ids = map("id", contactsTransactions); - expect(ids).toContain(response.contactsTransactions[9].id); - }); - - it("should create a payment", () => { - const sender: User = getAllUsers()[0]; - const receiver: User = getAllUsers()[1]; - const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; - - const paymentDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Payment: ${sender.id} to ${receiver.id}`, - amount: getFakeAmount(), - privacyLevel: DefaultPrivacyLevel.public, - status: TransactionStatus.pending, - }; - - const result = createTransaction(sender.id, "payment", paymentDetails); - expect(result.id).toBeDefined(); - expect(result.status).toEqual("complete"); - expect(result.requestStatus).not.toBeDefined(); - }); - - it("should create a request", () => { - const sender: User = getAllUsers()[0]; - const receiver: User = getAllUsers()[1]; - const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; - - const requestDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Request: ${sender.id} to ${receiver.id}`, - amount: getFakeAmount(), - privacyLevel: DefaultPrivacyLevel.public, - status: TransactionStatus.pending, - }; - - const result = createTransaction(sender.id, "request", requestDetails); - expect(result.id).toBeDefined(); - expect(result.status).toEqual("pending"); - expect(result.requestStatus).toEqual("pending"); - }); - - it("should create a payment and find it in the personal transactions", () => { - const sender: User = getAllUsers()[0]; - const receiver: User = getAllUsers()[1]; - const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; - - const paymentDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Payment: ${sender.id} to ${receiver.id}`, - amount: getFakeAmount(), - privacyLevel: DefaultPrivacyLevel.private, - status: TransactionStatus.pending, - }; - - const payment = createTransaction(sender.id, "payment", paymentDetails); - expect(payment.id).toBeDefined(); - - const personalTransactions: Transaction[] = getTransactionsForUserByObj(sender.id, {}); - const ids = map("id", personalTransactions); - expect(ids).toContain(payment.id); - }); - - it("should reject (update) a transaction", () => { - const user: User = getAllUsers()[0]; - - const transactions = getTransactionsByUserId(user.id); - expect(transactions.length).toBeGreaterThanOrEqual(transactionsPerUser); - - const transaction = transactions[0]; - expect(transaction.requestStatus).not.toEqual("rejected"); - - const edits: Partial = { - requestStatus: TransactionRequestStatus.rejected, - }; - updateTransactionById(transaction.id, edits); - - const updatedTransaction = getTransactionById(transaction.id); - expect(updatedTransaction.requestStatus).toEqual("rejected"); - }); - - it("should accept (update) a transaction", () => { - const user: User = getAllUsers()[0]; - - const transactions = getTransactionsByUserId(user.id); - expect(transactions.length).toBeGreaterThanOrEqual(transactionsPerUser); - - const transaction = transactions[0]; - expect(transaction.requestStatus).not.toEqual("accepted"); - - const edits: Partial = { - requestStatus: TransactionRequestStatus.accepted, - }; - updateTransactionById(transaction.id, edits); - - const updatedTransaction = getTransactionById(transaction.id); - expect(updatedTransaction.requestStatus).toEqual("accepted"); - }); - - it("should add additional fields (e.g. retreiverName, senderName, etc) to a list of transactions for a user for API response", () => { - const userToLookup: User = getAllUsers()[0]; - - const result = getPublicTransactionsDefaultSort(userToLookup.id); - - const transaction = result.publicTransactions[0]; - const { receiverId, senderId, receiverName, senderName } = transaction; - const receiver = getUserById(receiverId); - const sender = getUserById(senderId); - - expect(receiverName).toBe(`${receiver.firstName} ${receiver.lastName}`); - expect(senderName).toBe(`${sender.firstName} ${sender.lastName}`); - expect(transaction.likes).toBeDefined(); - expect(transaction.comments).toBeDefined(); - }); - - it.skip("should create a payment and withdrawal (bank transfer) for remaining balance", () => { - const sender: User = getAllUsers()[0]; - const receiver: User = getAllUsers()[1]; - const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; - const firstPaymentAmount = 1000; - const secondPaymentAmount = 500; - - const receiverTransactions = getTransactionsByUserId(receiver.id); - expect(receiverTransactions.length).toBeGreaterThan(1); - - console.log("sender balance:", sender.balance + 1000); - const paymentDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Payment: ${sender.id} to ${receiver.id}`, - amount: sender.balance + firstPaymentAmount, - privacyLevel: DefaultPrivacyLevel.public, - status: TransactionStatus.pending, - }; - - const transaction = createTransaction(sender.id, "payment", paymentDetails); - expect(transaction.id).toBeDefined(); - expect(transaction.status).toEqual("complete"); - expect(transaction.requestStatus).not.toBeDefined(); - - const updatedSender: User = getAllUsers()[0]; - expect(updatedSender.balance).toBe(0); - - const withdrawal = getBankTransferByTransactionId(transaction.id); - expect(withdrawal.type).toBe(BankTransferType.withdrawal); - expect(withdrawal.amount).toBe(firstPaymentAmount); - - // second transaction - $500 - const secondPaymentDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Payment: ${sender.id} to ${receiver.id}`, - amount: secondPaymentAmount, - privacyLevel: DefaultPrivacyLevel.public, - status: TransactionStatus.pending, - }; - const secondTransaction = createTransaction(sender.id, "payment", secondPaymentDetails); - expect(secondTransaction.id).toBeDefined(); - expect(secondTransaction.status).toEqual("complete"); - expect(secondTransaction.requestStatus).not.toBeDefined(); - - const secondUpdatedSender: User = getAllUsers()[0]; - expect(secondUpdatedSender.balance).toBe(0); - - const secondWithdrawal = getBankTransferByTransactionId(secondTransaction.id); - expect(secondWithdrawal.type).toBe(BankTransferType.withdrawal); - expect(secondWithdrawal.amount).toBe(secondPaymentAmount); - - // Verify Deposit Transactions for Receiver - const updatedReceiverTransactions = getTransactionsByUserId(receiver.id); - - expect(updatedReceiverTransactions.length).toBe(receiverTransactions.length + 2); - - // Verify Receiver's Updated App Balance - const updatedReceiver: User = getAllUsers()[1]; - expect(updatedReceiver.balance).toBe( - receiver.balance + firstPaymentAmount + secondPaymentAmount - ); - }); - - it.skip("should create a request and withdrawal (bank transfer) for remaining balance", () => { - const sender: User = getAllUsers()[0]; - const receiver: User = getAllUsers()[1]; - const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; - const requestAmount = 100; - - const receiverTransactions = getTransactionsByUserId(receiver.id); - expect(receiverTransactions.length).toBeGreaterThan(1); - - const requestDetails: TransactionPayload = { - source: senderBankAccount.id!, - senderId: sender.id, - receiverId: receiver.id, - description: `Request: ${sender.id} to ${receiver.id}`, - amount: requestAmount, - privacyLevel: DefaultPrivacyLevel.public, - status: TransactionStatus.pending, - }; - - const transaction = createTransaction(sender.id, "request", requestDetails); - expect(transaction.id).toBeDefined(); - expect(transaction.status).toEqual("pending"); - expect(transaction.requestStatus).toBe(TransactionRequestStatus.pending); - - const edits: Partial = { - requestStatus: TransactionRequestStatus.accepted, - }; - updateTransactionById(transaction.id, edits); - - const updatedTransaction = getTransactionById(transaction.id); - expect(updatedTransaction.requestStatus).toEqual("accepted"); - - const updatedReceiver: User = getAllUsers()[1]; - expect(updatedReceiver.balance).toBe(receiver.balance + requestAmount); - - // Verify Deposit Transactions for Sender - const updatedSenderTransactions = getTransactionsByUserId(sender.id); - - expect(updatedSenderTransactions.length).toBe(receiverTransactions.length + 2); - - // Verify Sender's Updated App Balance - const updatedSender: User = getAllUsers()[0]; - expect(updatedSender.balance).toBe(sender.balance - requestAmount); - }); +describe("Transactions", () => { + // beforeEach(() => { + // seedDatabase(); + // }); + // it("should retrieve a list of all transactions", () => { + // expect(getAllTransactions().length).toBe(totalTransactions); + // }); + // it("should retrieve a list of all public transactions", () => { + // expect(getAllPublicTransactions().length).toBeGreaterThan(transactionsPerUser); + // expect(getAllPublicTransactions().length).toBeLessThan(totalTransactions); + // }); + // it("should retrieve a list of transactions for a user (user is receiver)", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result: Transaction[] = getTransactionsForUserByObj(userToLookup.id, { + // status: "complete", + // }); + // expect(result[0].receiverId).toBe(userToLookup.id); + // }); + // it("should retrieve a list of transactions for a user (user is sender)", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result: Transaction[] = getTransactionsForUserByObj(userToLookup.id, {}); + // expect(result.pop()!.senderId).toBe(userToLookup.id); + // }); + // it("should retrieve a list of transactions for a users contacts", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result: Transaction[] = getTransactionsForUserContacts(userToLookup.id); + // expect(result.length).toBeGreaterThan(transactionsPerUser); + // expect(result.length).toBeLessThan(totalTransactions); + // }); + // it("should retrieve a list of transactions for a users contacts - between date range", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result: Transaction[] = getTransactionsForUserContacts(userToLookup.id, { + // dateRangeStart: new Date("Mar 09 2023"), + // dateRangeEnd: new Date("Mar 09 2024"), + // }); + // expect(result.length).toBeGreaterThan(1); + // }); + // it("should retrieve a list of public transactions, default sort", () => { + // const user: User = getAllUsers()[0]; + // const contactsTransactions: Transaction[] = getTransactionsForUserContacts(user.id); + // expect(contactsTransactions.length).toBeGreaterThan(1); + // expect(contactsTransactions.length).toBeLessThan(totalTransactions); + // const response = getPublicTransactionsDefaultSort(user.id); + // expect(response.contactsTransactions.length).toBeGreaterThan(1); + // expect(response.contactsTransactions.length).toBeLessThan(totalTransactions); + // expect(response.publicTransactions.length).toBeGreaterThan(1); + // expect(response.publicTransactions.length).toBeLessThan(totalTransactions); + // const ids = map("id", contactsTransactions); + // expect(ids).toContain(response.contactsTransactions[9].id); + // }); + // it("should create a payment", () => { + // const sender: User = getAllUsers()[0]; + // const receiver: User = getAllUsers()[1]; + // const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; + // const paymentDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Payment: ${sender.id} to ${receiver.id}`, + // amount: getFakeAmount(), + // privacyLevel: DefaultPrivacyLevel.public, + // status: TransactionStatus.pending, + // }; + // const result = createTransaction(sender.id, "payment", paymentDetails); + // expect(result.id).toBeDefined(); + // expect(result.status).toEqual("complete"); + // expect(result.requestStatus).not.toBeDefined(); + // }); + // it("should create a request", () => { + // const sender: User = getAllUsers()[0]; + // const receiver: User = getAllUsers()[1]; + // const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; + // const requestDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Request: ${sender.id} to ${receiver.id}`, + // amount: getFakeAmount(), + // privacyLevel: DefaultPrivacyLevel.public, + // status: TransactionStatus.pending, + // }; + // const result = createTransaction(sender.id, "request", requestDetails); + // expect(result.id).toBeDefined(); + // expect(result.status).toEqual("pending"); + // expect(result.requestStatus).toEqual("pending"); + // }); + // it("should create a payment and find it in the personal transactions", () => { + // const sender: User = getAllUsers()[0]; + // const receiver: User = getAllUsers()[1]; + // const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; + // const paymentDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Payment: ${sender.id} to ${receiver.id}`, + // amount: getFakeAmount(), + // privacyLevel: DefaultPrivacyLevel.private, + // status: TransactionStatus.pending, + // }; + // const payment = createTransaction(sender.id, "payment", paymentDetails); + // expect(payment.id).toBeDefined(); + // const personalTransactions: Transaction[] = getTransactionsForUserByObj(sender.id, {}); + // const ids = map("id", personalTransactions); + // expect(ids).toContain(payment.id); + // }); + // it("should reject (update) a transaction", () => { + // const user: User = getAllUsers()[0]; + // const transactions = getTransactionsByUserId(user.id); + // expect(transactions.length).toBeGreaterThanOrEqual(transactionsPerUser); + // const transaction = transactions[0]; + // expect(transaction.requestStatus).not.toEqual("rejected"); + // const edits: Partial = { + // requestStatus: TransactionRequestStatus.rejected, + // }; + // updateTransactionById(transaction.id, edits); + // const updatedTransaction = getTransactionById(transaction.id); + // expect(updatedTransaction.requestStatus).toEqual("rejected"); + // }); + // it("should accept (update) a transaction", () => { + // const user: User = getAllUsers()[0]; + // const transactions = getTransactionsByUserId(user.id); + // expect(transactions.length).toBeGreaterThanOrEqual(transactionsPerUser); + // const transaction = transactions[0]; + // expect(transaction.requestStatus).not.toEqual("accepted"); + // const edits: Partial = { + // requestStatus: TransactionRequestStatus.accepted, + // }; + // updateTransactionById(transaction.id, edits); + // const updatedTransaction = getTransactionById(transaction.id); + // expect(updatedTransaction.requestStatus).toEqual("accepted"); + // }); + // it("should add additional fields (e.g. retreiverName, senderName, etc) to a list of transactions for a user for API response", () => { + // const userToLookup: User = getAllUsers()[0]; + // const result = getPublicTransactionsDefaultSort(userToLookup.id); + // const transaction = result.publicTransactions[0]; + // const { receiverId, senderId, receiverName, senderName } = transaction; + // const receiver = getUserById(receiverId); + // const sender = getUserById(senderId); + // expect(receiverName).toBe(`${receiver.firstName} ${receiver.lastName}`); + // expect(senderName).toBe(`${sender.firstName} ${sender.lastName}`); + // expect(transaction.likes).toBeDefined(); + // expect(transaction.comments).toBeDefined(); + // }); + // it.skip("should create a payment and withdrawal (bank transfer) for remaining balance", () => { + // const sender: User = getAllUsers()[0]; + // const receiver: User = getAllUsers()[1]; + // const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; + // const firstPaymentAmount = 1000; + // const secondPaymentAmount = 500; + // const receiverTransactions = getTransactionsByUserId(receiver.id); + // expect(receiverTransactions.length).toBeGreaterThan(1); + // console.log("sender balance:", sender.balance + 1000); + // const paymentDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Payment: ${sender.id} to ${receiver.id}`, + // amount: sender.balance + firstPaymentAmount, + // privacyLevel: DefaultPrivacyLevel.public, + // status: TransactionStatus.pending, + // }; + // const transaction = createTransaction(sender.id, "payment", paymentDetails); + // expect(transaction.id).toBeDefined(); + // expect(transaction.status).toEqual("complete"); + // expect(transaction.requestStatus).not.toBeDefined(); + // const updatedSender: User = getAllUsers()[0]; + // expect(updatedSender.balance).toBe(0); + // const withdrawal = getBankTransferByTransactionId(transaction.id); + // expect(withdrawal.type).toBe(BankTransferType.withdrawal); + // expect(withdrawal.amount).toBe(firstPaymentAmount); + // // second transaction - $500 + // const secondPaymentDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Payment: ${sender.id} to ${receiver.id}`, + // amount: secondPaymentAmount, + // privacyLevel: DefaultPrivacyLevel.public, + // status: TransactionStatus.pending, + // }; + // const secondTransaction = createTransaction(sender.id, "payment", secondPaymentDetails); + // expect(secondTransaction.id).toBeDefined(); + // expect(secondTransaction.status).toEqual("complete"); + // expect(secondTransaction.requestStatus).not.toBeDefined(); + // const secondUpdatedSender: User = getAllUsers()[0]; + // expect(secondUpdatedSender.balance).toBe(0); + // const secondWithdrawal = getBankTransferByTransactionId(secondTransaction.id); + // expect(secondWithdrawal.type).toBe(BankTransferType.withdrawal); + // expect(secondWithdrawal.amount).toBe(secondPaymentAmount); + // // Verify Deposit Transactions for Receiver + // const updatedReceiverTransactions = getTransactionsByUserId(receiver.id); + // expect(updatedReceiverTransactions.length).toBe(receiverTransactions.length + 2); + // // Verify Receiver's Updated App Balance + // const updatedReceiver: User = getAllUsers()[1]; + // expect(updatedReceiver.balance).toBe( + // receiver.balance + firstPaymentAmount + secondPaymentAmount + // ); + // }); + // it.skip("should create a request and withdrawal (bank transfer) for remaining balance", () => { + // const sender: User = getAllUsers()[0]; + // const receiver: User = getAllUsers()[1]; + // const senderBankAccount = getBankAccountsByUserId(sender.id)[0]; + // const requestAmount = 100; + // const receiverTransactions = getTransactionsByUserId(receiver.id); + // expect(receiverTransactions.length).toBeGreaterThan(1); + // const requestDetails: TransactionPayload = { + // source: senderBankAccount.id!, + // senderId: sender.id, + // receiverId: receiver.id, + // description: `Request: ${sender.id} to ${receiver.id}`, + // amount: requestAmount, + // privacyLevel: DefaultPrivacyLevel.public, + // status: TransactionStatus.pending, + // }; + // const transaction = createTransaction(sender.id, "request", requestDetails); + // expect(transaction.id).toBeDefined(); + // expect(transaction.status).toEqual("pending"); + // expect(transaction.requestStatus).toBe(TransactionRequestStatus.pending); + // const edits: Partial = { + // requestStatus: TransactionRequestStatus.accepted, + // }; + // updateTransactionById(transaction.id, edits); + // const updatedTransaction = getTransactionById(transaction.id); + // expect(updatedTransaction.requestStatus).toEqual("accepted"); + // const updatedReceiver: User = getAllUsers()[1]; + // expect(updatedReceiver.balance).toBe(receiver.balance + requestAmount); + // // Verify Deposit Transactions for Sender + // const updatedSenderTransactions = getTransactionsByUserId(sender.id); + // expect(updatedSenderTransactions.length).toBe(receiverTransactions.length + 2); + // // Verify Sender's Updated App Balance + // const updatedSender: User = getAllUsers()[0]; + // expect(updatedSender.balance).toBe(sender.balance - requestAmount); + // }); }); diff --git a/src/__tests__/users.test.ts b/src/__tests__/users.test.ts index 56e757d51..248933e17 100644 --- a/src/__tests__/users.test.ts +++ b/src/__tests__/users.test.ts @@ -3,51 +3,38 @@ import { seedDatabase, getAllUsers, searchUsers } from "../../backend/database"; import { User } from "../models"; -describe.skip("Users", () => { - beforeEach(() => { - seedDatabase(); - }); - - it("should get a user by email address", () => { - const userToLookup: User = getAllUsers()[0]; - const { email } = userToLookup; - - const users = searchUsers(email); - - expect(users.length).toBeGreaterThanOrEqual(1); - expect(users[0].id).toBe(userToLookup.id); - }); - - it("should get a user by username", () => { - const userToLookup: User = getAllUsers()[0]; - const { username } = userToLookup; - - const users = searchUsers(username); - - expect(users.length).toBeGreaterThanOrEqual(1); - expect(users[0].id).toBe(userToLookup.id); - }); - - it("should get a user by phone number", () => { - const userToLookup: User = getAllUsers()[0]; - const { phoneNumber } = userToLookup; - - const users = searchUsers(phoneNumber); - - expect(users.length).toBeGreaterThanOrEqual(1); - expect(users[0].id).toBe(userToLookup.id); - }); - - it("should get a list of users by alpha (username, email) (fuzzy match)", () => { - const userToLookup: User = getAllUsers()[0]; - const users = searchUsers(userToLookup.firstName); - - expect(users.length).toBeGreaterThanOrEqual(1); - }); - - it("should get a list of users by phone (fuzzy match)", () => { - const users = searchUsers("201"); - - expect(users.length).toBeGreaterThanOrEqual(1); - }); +describe("Users", () => { + // beforeEach(() => { + // seedDatabase(); + // }); + // it("should get a user by email address", () => { + // const userToLookup: User = getAllUsers()[0]; + // const { email } = userToLookup; + // const users = searchUsers(email); + // expect(users.length).toBeGreaterThanOrEqual(1); + // expect(users[0].id).toBe(userToLookup.id); + // }); + // it("should get a user by username", () => { + // const userToLookup: User = getAllUsers()[0]; + // const { username } = userToLookup; + // const users = searchUsers(username); + // expect(users.length).toBeGreaterThanOrEqual(1); + // expect(users[0].id).toBe(userToLookup.id); + // }); + // it("should get a user by phone number", () => { + // const userToLookup: User = getAllUsers()[0]; + // const { phoneNumber } = userToLookup; + // const users = searchUsers(phoneNumber); + // expect(users.length).toBeGreaterThanOrEqual(1); + // expect(users[0].id).toBe(userToLookup.id); + // }); + // it("should get a list of users by alpha (username, email) (fuzzy match)", () => { + // const userToLookup: User = getAllUsers()[0]; + // const users = searchUsers(userToLookup.firstName); + // expect(users.length).toBeGreaterThanOrEqual(1); + // }); + // it("should get a list of users by phone (fuzzy match)", () => { + // const users = searchUsers("201"); + // expect(users.length).toBeGreaterThanOrEqual(1); + // }); });