From 32aacb69bd9625b0487d67e7e5551d60491e3f3a Mon Sep 17 00:00:00 2001 From: Pontus Abrahamsson Date: Fri, 28 Jun 2024 15:35:14 +0200 Subject: [PATCH 1/2] Transaction amounts --- .../__snapshots__/transform.test.ts.snap | 45 +----- .../src/providers/plaid/transform.test.ts | 4 +- apps/engine/src/providers/plaid/transform.ts | 40 +++-- .../__snapshots__/transform.test.ts.snap | 60 +++++++ .../src/providers/teller/transform.test.ts | 152 +++++++++--------- apps/engine/src/providers/teller/transform.ts | 9 +- apps/engine/src/utils/account.test.ts | 30 +--- apps/engine/src/utils/account.ts | 34 ---- packages/jobs/src/transactions/sync.ts | 25 ++- .../__snapshots__/transform.test.ts.snap | 4 +- packages/providers/src/plaid/plaid-api.ts | 12 +- packages/providers/src/plaid/transform.ts | 37 +++-- .../__snapshots__/transform.test.ts.snap | 8 +- .../providers/src/teller/transform.test.ts | 4 +- packages/providers/src/teller/transform.ts | 5 +- 15 files changed, 221 insertions(+), 248 deletions(-) diff --git a/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap b/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap index 97deb5dcf3..bcf2e9736f 100644 --- a/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap +++ b/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap @@ -4,10 +4,10 @@ exports[`Transform pending transaction 1`] = ` { "amount": 5.4, "balance": null, - "category": "income", + "category": "travel", "currency": "CAD", "date": "2024-02-24", - "description": null, + "description": "Uber", "internal_id": "NxkDjlyk45cQoDm5PEqJuKJaw6qrj9cy89zBA", "method": "other", "name": "Uber 063015 SF**POOL**", @@ -17,9 +17,9 @@ exports[`Transform pending transaction 1`] = ` exports[`Transform income transaction 1`] = ` { - "amount": 500, + "amount": 1500, "balance": null, - "category": "income", + "category": "travel", "currency": "CAD", "date": "2024-02-22", "description": null, @@ -29,40 +29,3 @@ exports[`Transform income transaction 1`] = ` "status": "posted", } `; - -exports[`Transform type transfer 1`] = ` -{ - "amount": 5.4, - "balance": null, - "category": "transfer", - "currency": "CAD", - "date": "2024-02-24", - "description": null, - "internal_id": "NxkDjlyk45cQoDm5PEqJuKJaw6qrj9cy89zBA", - "method": "transfer", - "name": "Uber 063015 SF**POOL**", - "status": "pending", -} -`; - -exports[`Transform accounts 1`] = ` -{ - "currency": "CAD", - "id": "kKZWQnoZVqcBeN71qdyoh8mVoErgb7tL7gmBL", - "institution": { - "id": "ins_100546", - "logo": null, - "name": "American Funds Retirement Solutions", - }, - "name": "Plaid Mortgage", - "provider": "plaid", - "type": "other_asset", -} -`; - -exports[`Transform account balance 1`] = ` -{ - "amount": 2000, - "currency": "USD", -} -`; diff --git a/apps/engine/src/providers/plaid/transform.test.ts b/apps/engine/src/providers/plaid/transform.test.ts index 8942236071..a06883d860 100644 --- a/apps/engine/src/providers/plaid/transform.test.ts +++ b/apps/engine/src/providers/plaid/transform.test.ts @@ -76,14 +76,14 @@ test("Transform pending transaction", () => { ).toMatchSnapshot(); }); -test("Transform income transaction", () => { +test.only("Transform income transaction", () => { expect( transformTransaction({ accountType: "depository", transaction: { account_id: "AG7EkLW7DRSVaN8Z75jMT1DJN51QpWc9LKB7w", account_owner: null, - amount: -500, + amount: 1500, authorized_date: "2024-02-22", authorized_datetime: null, category: ["Travel", "Airlines and Aviation Services"], diff --git a/apps/engine/src/providers/plaid/transform.ts b/apps/engine/src/providers/plaid/transform.ts index 653a15216c..a010fb1a58 100644 --- a/apps/engine/src/providers/plaid/transform.ts +++ b/apps/engine/src/providers/plaid/transform.ts @@ -1,8 +1,4 @@ -import { - type AccountType, - formatAmountForAsset, - getType, -} from "@/utils/account"; +import { type AccountType, getType } from "@/utils/account"; import { capitalCase } from "change-case"; import type { Transaction, TransactionCode } from "plaid"; import type { @@ -125,6 +121,27 @@ export const mapTransactionCategory = ({ return null; }; +const formatAmout = (amount: number) => { + // Positive values when money moves out of the account; negative values when money moves in. + // For example, debit card purchases are positive; credit card payments, direct deposits, and refunds are negative. + return +(amount * -1); +}; + +const transformDescription = (transaction: Transaction) => { + if (transaction?.original_description) { + return capitalCase(transaction.original_description); + } + + if ( + transaction?.merchant_name && + transaction?.merchant_name !== transaction.name + ) { + return transaction?.merchant_name; + } + + return null; +}; + type TransformTransactionPayload = { transaction: TransformTransaction; accountType: AccountType; @@ -132,24 +149,17 @@ type TransformTransactionPayload = { export const transformTransaction = ({ transaction, - accountType, }: TransformTransactionPayload): BaseTransaction => { const method = mapTransactionMethod(transaction?.transaction_code); - - const amount = formatAmountForAsset({ - amount: transaction.amount, - type: accountType, - }); + const amount = formatAmout(transaction.amount); return { date: transaction.date, name: transaction.name, - description: transaction?.original_description - ? capitalCase(transaction.original_description) - : null, + description: transformDescription(transaction), method, internal_id: transaction.transaction_id, - amount, + amount: formatAmout(amount), currency: transaction.iso_currency_code || transaction.unofficial_currency_code || diff --git a/apps/engine/src/providers/teller/__snapshots__/transform.test.ts.snap b/apps/engine/src/providers/teller/__snapshots__/transform.test.ts.snap index ef2f7b7b69..8b130f509b 100644 --- a/apps/engine/src/providers/teller/__snapshots__/transform.test.ts.snap +++ b/apps/engine/src/providers/teller/__snapshots__/transform.test.ts.snap @@ -1,5 +1,65 @@ // Bun Snapshot v1, https://goo.gl/fbAQLP +exports[`Transform pending transaction 1`] = ` +{ + "amount": 83.62, + "balance": null, + "category": "income", + "currency": "USD", + "date": "2024-03-05", + "description": "Bank Of Many", + "internal_id": "txn_os41r5u90e29shubl2000", + "method": "other", + "name": "Online Check Deposit", + "status": "pending", +} +`; + +exports[`Transform card payment transaction 1`] = ` +{ + "amount": -68.9, + "balance": "83431.46", + "category": null, + "currency": "USD", + "date": "2024-03-01", + "description": "Nordstrom", + "internal_id": "txn_os41r5u90e29shubl2005", + "method": "card_purchase", + "name": "Nordstrom", + "status": "posted", +} +`; + +exports[`Transform income transaction 1`] = ` +{ + "amount": -20.21, + "balance": "83296.40", + "category": null, + "currency": "USD", + "date": "2024-03-03", + "description": "Exxon Mobil", + "internal_id": "txn_os41r5u90e29shubl2002", + "method": "card_purchase", + "name": "Exxon Mobil", + "status": "posted", +} +`; + +exports[`Transform type transfer 1`] = ` +{ + "amount": -37.99, + "balance": "85897.25", + "category": "transfer", + "currency": "USD", + "date": "2024-01-27", + "description": "Yourself", + "internal_id": "txn_os41r5ua0e29shubl2001", + "method": "transfer", + "name": "Recurring Transfer To Savings", + "status": "posted", +} +`; + exports[`Transform accounts 1`] = ` { "currency": "USD", diff --git a/apps/engine/src/providers/teller/transform.test.ts b/apps/engine/src/providers/teller/transform.test.ts index 8a56771e7c..34cd82d0a1 100644 --- a/apps/engine/src/providers/teller/transform.test.ts +++ b/apps/engine/src/providers/teller/transform.test.ts @@ -4,26 +4,28 @@ import { transformAccount, transformTransaction } from "./transform"; test("Transform pending transaction", () => { expect( transformTransaction({ - type: "check", - status: "pending", - running_balance: null, - links: { - self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2000", - account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", - }, - id: "txn_os41r5u90e29shubl2000", - details: { - processing_status: "complete", - counterparty: { - type: "organization", - name: "BANK OF MANY", + transaction: { + type: "check", + status: "pending", + running_balance: null, + links: { + self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2000", + account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", + }, + id: "txn_os41r5u90e29shubl2000", + details: { + processing_status: "complete", + counterparty: { + type: "organization", + name: "BANK OF MANY", + }, + category: "general", }, - category: "general", + description: "Online Check Deposit", + date: "2024-03-05", + amount: "83.62", + account_id: "acc_os41qe3a66ks2djhss000", }, - description: "Online Check Deposit", - date: "2024-03-05", - amount: "83.62", - account_id: "acc_os41qe3a66ks2djhss000", }) ).toMatchSnapshot(); }); @@ -31,26 +33,28 @@ test("Transform pending transaction", () => { test("Transform card payment transaction", () => { expect( transformTransaction({ - type: "card_payment", - status: "posted", - running_balance: "83431.46", - links: { - self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2005", - account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", - }, - id: "txn_os41r5u90e29shubl2005", - details: { - processing_status: "complete", - counterparty: { - type: "organization", - name: "NORDSTROM", + transaction: { + type: "card_payment", + status: "posted", + running_balance: "83431.46", + links: { + self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2005", + account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", + }, + id: "txn_os41r5u90e29shubl2005", + details: { + processing_status: "complete", + counterparty: { + type: "organization", + name: "NORDSTROM", + }, + category: "shopping", }, - category: "shopping", + description: "Nordstrom", + date: "2024-03-01", + amount: "-68.90", + account_id: "acc_os41qe3a66ks2djhss000", }, - description: "Nordstrom", - date: "2024-03-01", - amount: "-68.90", - account_id: "acc_os41qe3a66ks2djhss000", }) ).toMatchSnapshot(); }); @@ -58,26 +62,28 @@ test("Transform card payment transaction", () => { test("Transform income transaction", () => { expect( transformTransaction({ - type: "card_payment", - status: "posted", - running_balance: "83296.40", - links: { - self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2002", - account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", - }, - id: "txn_os41r5u90e29shubl2002", - details: { - processing_status: "complete", - counterparty: { - type: "organization", - name: "EXXON MOBIL", + transaction: { + type: "card_payment", + status: "posted", + running_balance: "83296.40", + links: { + self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl2002", + account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", + }, + id: "txn_os41r5u90e29shubl2002", + details: { + processing_status: "complete", + counterparty: { + type: "organization", + name: "EXXON MOBIL", + }, + category: "fuel", }, - category: "fuel", + description: "Exxon Mobil", + date: "2024-03-03", + amount: "-20.21", + account_id: "acc_os41qe3a66ks2djhss000", }, - description: "Exxon Mobil", - date: "2024-03-03", - amount: "-20.21", - account_id: "acc_os41qe3a66ks2djhss000", }) ).toMatchSnapshot(); }); @@ -85,26 +91,28 @@ test("Transform income transaction", () => { test("Transform type transfer", () => { expect( transformTransaction({ - type: "transfer", - status: "posted", - running_balance: "85897.25", - links: { - self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5ua0e29shubl2001", - account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", - }, - id: "txn_os41r5ua0e29shubl2001", - details: { - processing_status: "complete", - counterparty: { - type: "person", - name: "YOURSELF", + transaction: { + type: "transfer", + status: "posted", + running_balance: "85897.25", + links: { + self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5ua0e29shubl2001", + account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000", + }, + id: "txn_os41r5ua0e29shubl2001", + details: { + processing_status: "complete", + counterparty: { + type: "person", + name: "YOURSELF", + }, + category: "general", }, - category: "general", + description: "Recurring Transfer to Savings", + date: "2024-01-27", + amount: "-37.99", + account_id: "acc_os41qe3a66ks2djhss000", }, - description: "Recurring Transfer to Savings", - date: "2024-01-27", - amount: "-37.99", - account_id: "acc_os41qe3a66ks2djhss000", }) ).toMatchSnapshot(); }); diff --git a/apps/engine/src/providers/teller/transform.ts b/apps/engine/src/providers/teller/transform.ts index fe11e36b9b..6b9d92b02d 100644 --- a/apps/engine/src/providers/teller/transform.ts +++ b/apps/engine/src/providers/teller/transform.ts @@ -1,8 +1,4 @@ -import { - type AccountType, - formatAmountForAsset, - getType, -} from "@/utils/account"; +import { getType } from "@/utils/account"; import { capitalCase } from "change-case"; import type { Account as BaseAccount, @@ -98,6 +94,7 @@ export const transformTransaction = ({ }: TransformTransactionPayload): BaseTransaction => { const method = mapTransactionMethod(transaction.type); const amount = +transaction.amount; + const name = capitalCase(transaction.description); const description = (transaction?.details?.counterparty?.name && capitalCase(transaction.details.counterparty.name)) || @@ -105,7 +102,7 @@ export const transformTransaction = ({ return { date: transaction.date, - name: transaction.description && capitalCase(transaction.description), + name, description, method, internal_id: transaction.id, diff --git a/apps/engine/src/utils/account.test.ts b/apps/engine/src/utils/account.test.ts index cbb74edb7e..1d708371d4 100644 --- a/apps/engine/src/utils/account.test.ts +++ b/apps/engine/src/utils/account.test.ts @@ -1,36 +1,8 @@ import { expect, test } from "bun:test"; -import { - AccountType, - formatAmountForAsset, - getClassification, - getType, -} from "./account"; +import { getType } from "./account"; test("Get account type", () => { expect(getType("depository")).toBe("depository"); expect(getType("credit")).toBe("credit"); expect(getType("blah")).toBe("other_asset"); }); - -test("Get classification", () => { - expect(getClassification(AccountType.CREDIT)).toBe("liability"); - expect(getClassification(AccountType.LOAN)).toBe("liability"); - expect(getClassification(AccountType.OTHER_LIABILITY)).toBe("liability"); - expect(getClassification(AccountType.OTHER_ASSET)).toBe("asset"); -}); - -test("Format amount", () => { - expect( - formatAmountForAsset({ - amount: 1000, - type: AccountType.CREDIT, - }) - ).toBe(1000); - - expect( - formatAmountForAsset({ - amount: 1000, - type: AccountType.DEPOSITORY, - }) - ).toBe(-1000); -}); diff --git a/apps/engine/src/utils/account.ts b/apps/engine/src/utils/account.ts index 2cb08f1b0a..b3f7c7dd33 100644 --- a/apps/engine/src/utils/account.ts +++ b/apps/engine/src/utils/account.ts @@ -6,11 +6,6 @@ export enum AccountType { OTHER_LIABILITY = "other_liability", } -enum AccountClassification { - asset = "asset", - liability = "liability", -} - export function getType(type: string): AccountType { switch (type) { case "depository": @@ -21,32 +16,3 @@ export function getType(type: string): AccountType { return AccountType.OTHER_ASSET; } } - -export function getClassification(type: AccountType): AccountClassification { - switch (type) { - case AccountType.CREDIT: - case AccountType.LOAN: - case AccountType.OTHER_LIABILITY: - return AccountClassification.liability; - default: - return AccountClassification.asset; - } -} - -type FormatAmountForAssetParams = { - amount: number; - type: AccountType; -}; - -export function formatAmountForAsset({ - amount, - type, -}: FormatAmountForAssetParams) { - const classification = getClassification(type); - - if (classification === AccountClassification.asset) { - return +(amount * -1); - } - - return +amount; -} diff --git a/packages/jobs/src/transactions/sync.ts b/packages/jobs/src/transactions/sync.ts index eb966b5d22..c232ea94ef 100644 --- a/packages/jobs/src/transactions/sync.ts +++ b/packages/jobs/src/transactions/sync.ts @@ -76,27 +76,20 @@ client.defineJob({ return null; } - const { - error: transactionsError, - data: transactionsData, - statusText, - } = await supabase - .from("transactions") - .upsert(transactions, { - onConflict: "internal_id", - ignoreDuplicates: true, - }) - .select("*"); + const { error: transactionsError, data: transactionsData } = + await supabase + .from("transactions") + .upsert(transactions, { + onConflict: "internal_id", + ignoreDuplicates: true, + }) + .select("*"); if (transactionsError) { await io.logger.error("Transactions error", transactionsError); } - if ( - statusText === "Created" && - transactionsData && - transactionsData?.length > 0 - ) { + if (transactionsData && transactionsData?.length > 0) { await io.sendEvent("🔔 Send notifications", { name: Events.TRANSACTIONS_NOTIFICATION, payload: { diff --git a/packages/providers/src/plaid/__snapshots__/transform.test.ts.snap b/packages/providers/src/plaid/__snapshots__/transform.test.ts.snap index 7d0d127298..241374f724 100644 --- a/packages/providers/src/plaid/__snapshots__/transform.test.ts.snap +++ b/packages/providers/src/plaid/__snapshots__/transform.test.ts.snap @@ -8,7 +8,7 @@ exports[`Transform pending transaction 1`] = ` "category": "travel", "currency": "CAD", "date": "2024-02-24", - "description": null, + "description": "Uber", "internal_id": "123_NxkDjlyk45cQoDm5PEqJuKJaw6qrj9cy89zBA", "method": "other", "name": "Uber 063015 SF**POOL**", @@ -42,7 +42,7 @@ exports[`Transform type transfer 1`] = ` "category": "transfer", "currency": "CAD", "date": "2024-02-24", - "description": null, + "description": "Uber", "internal_id": "123_NxkDjlyk45cQoDm5PEqJuKJaw6qrj9cy89zBA", "method": "transfer", "name": "Uber 063015 SF**POOL**", diff --git a/packages/providers/src/plaid/plaid-api.ts b/packages/providers/src/plaid/plaid-api.ts index efa08c8d5a..578d4bba76 100644 --- a/packages/providers/src/plaid/plaid-api.ts +++ b/packages/providers/src/plaid/plaid-api.ts @@ -101,14 +101,10 @@ export class PlaidApi { cursor = data.next_cursor; } } - // NOTE: Plaid transactions for all accounts, we need to filter based on the - // Provided accountId - return ( - added - .filter((transaction) => transaction.account_id === accountId) - // NOTE: Remove pending transactions until upsert issue is fixed - .filter((transaction) => !transaction.pending) - ); + // NOTE: Fitler on accountId and pending + return added + .filter((transaction) => transaction.account_id === accountId) + .filter((transaction) => !transaction.pending); } async linkTokenCreate({ diff --git a/packages/providers/src/plaid/transform.ts b/packages/providers/src/plaid/transform.ts index 1934197600..93b81e9dcd 100644 --- a/packages/providers/src/plaid/transform.ts +++ b/packages/providers/src/plaid/transform.ts @@ -1,7 +1,4 @@ -import { - formatAmountForAsset, - getType, -} from "@midday/engine/src/utils/account"; +import { getType } from "@midday/engine/src/utils/account"; import { capitalCase } from "change-case"; import type { Transaction, TransactionCode } from "plaid"; import type { @@ -124,25 +121,39 @@ export const mapTransactionCategory = ({ return null; }; +const formatAmout = (amount: number) => { + // Positive values when money moves out of the account; negative values when money moves in. + // For example, debit card purchases are positive; credit card payments, direct deposits, and refunds are negative. + return +(amount * -1); +}; + +const transformDescription = (transaction: Transaction) => { + if (transaction?.original_description) { + return capitalCase(transaction.original_description); + } + + if ( + transaction?.merchant_name && + transaction?.merchant_name !== transaction.name + ) { + return transaction?.merchant_name; + } + + return null; +}; + export const transformTransaction = ({ transaction, - accountType, bankAccountId, teamId, }: TransformTransaction): BaseTransaction => { const method = mapTransactionMethod(transaction?.transaction_code); - - const amount = formatAmountForAsset({ - amount: transaction.amount, - type: accountType, - }); + const amount = formatAmout(+transaction.amount); return { date: transaction.date, name: transaction.name, - description: transaction?.original_description - ? capitalCase(transaction.original_description) - : null, + description: transformDescription(transaction), method, internal_id: `${teamId}_${transaction.transaction_id}`, amount, diff --git a/packages/providers/src/teller/__snapshots__/transform.test.ts.snap b/packages/providers/src/teller/__snapshots__/transform.test.ts.snap index 1f323e3dbe..c0c835158b 100644 --- a/packages/providers/src/teller/__snapshots__/transform.test.ts.snap +++ b/packages/providers/src/teller/__snapshots__/transform.test.ts.snap @@ -2,10 +2,10 @@ exports[`Transform pending transaction 1`] = ` { - "amount": 83.62, + "amount": -83.62, "balance": null, "bank_account_id": "123", - "category": "income", + "category": null, "currency": "USD", "date": "2024-03-05", "description": "Bank Of Many", @@ -36,10 +36,10 @@ exports[`Transform card payment transaction 1`] = ` exports[`Transform income transaction 1`] = ` { - "amount": -20.21, + "amount": 1000000, "balance": "83296.40", "bank_account_id": "123", - "category": null, + "category": "income", "currency": "USD", "date": "2024-03-03", "description": null, diff --git a/packages/providers/src/teller/transform.test.ts b/packages/providers/src/teller/transform.test.ts index 3e55121f69..7d722740a7 100644 --- a/packages/providers/src/teller/transform.test.ts +++ b/packages/providers/src/teller/transform.test.ts @@ -31,7 +31,7 @@ test("Transform pending transaction", () => { }, description: "Online Check Deposit", date: "2024-03-05", - amount: "83.62", + amount: "-83.62", account_id: "acc_os41qe3a66ks2djhss000", }, }) @@ -95,7 +95,7 @@ test("Transform income transaction", () => { }, description: "Exxon Mobil", date: "2024-03-03", - amount: "-20.21", + amount: "1000000", account_id: "acc_os41qe3a66ks2djhss000", }, }) diff --git a/packages/providers/src/teller/transform.ts b/packages/providers/src/teller/transform.ts index af9d71b4be..51e27537e9 100644 --- a/packages/providers/src/teller/transform.ts +++ b/packages/providers/src/teller/transform.ts @@ -1,7 +1,4 @@ -import { - formatAmountForAsset, - getType, -} from "@midday/engine/src/utils/account"; +import { getType } from "@midday/engine/src/utils/account"; import { capitalCase } from "change-case"; import type { Account as BaseAccount, From b933b15883417e92fc7610cdc12e89fcb2e9274d Mon Sep 17 00:00:00 2001 From: Pontus Abrahamsson Date: Fri, 28 Jun 2024 15:47:50 +0200 Subject: [PATCH 2/2] Transaction amounts --- .../__snapshots__/transform.test.ts.snap | 41 ++++++++++++++++++- .../src/providers/plaid/transform.test.ts | 4 +- apps/engine/src/providers/plaid/transform.ts | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap b/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap index bcf2e9736f..61309e9789 100644 --- a/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap +++ b/apps/engine/src/providers/plaid/__snapshots__/transform.test.ts.snap @@ -2,7 +2,7 @@ exports[`Transform pending transaction 1`] = ` { - "amount": 5.4, + "amount": -5.4, "balance": null, "category": "travel", "currency": "CAD", @@ -17,7 +17,7 @@ exports[`Transform pending transaction 1`] = ` exports[`Transform income transaction 1`] = ` { - "amount": 1500, + "amount": -1500, "balance": null, "category": "travel", "currency": "CAD", @@ -29,3 +29,40 @@ exports[`Transform income transaction 1`] = ` "status": "posted", } `; + +exports[`Transform type transfer 1`] = ` +{ + "amount": -31.53, + "balance": null, + "category": "transfer", + "currency": "CAD", + "date": "2024-02-24", + "description": "Uber", + "internal_id": "NxkDjlyk45cQoDm5PEqJuKJaw6qrj9cy89zBA", + "method": "transfer", + "name": "Uber 063015 SF**POOL**", + "status": "pending", +} +`; + +exports[`Transform accounts 1`] = ` +{ + "currency": "CAD", + "id": "kKZWQnoZVqcBeN71qdyoh8mVoErgb7tL7gmBL", + "institution": { + "id": "ins_100546", + "logo": null, + "name": "American Funds Retirement Solutions", + }, + "name": "Plaid Mortgage", + "provider": "plaid", + "type": "other_asset", +} +`; + +exports[`Transform account balance 1`] = ` +{ + "amount": 2000, + "currency": "USD", +} +`; diff --git a/apps/engine/src/providers/plaid/transform.test.ts b/apps/engine/src/providers/plaid/transform.test.ts index a06883d860..84ea671a6e 100644 --- a/apps/engine/src/providers/plaid/transform.test.ts +++ b/apps/engine/src/providers/plaid/transform.test.ts @@ -76,7 +76,7 @@ test("Transform pending transaction", () => { ).toMatchSnapshot(); }); -test.only("Transform income transaction", () => { +test("Transform income transaction", () => { expect( transformTransaction({ accountType: "depository", @@ -156,7 +156,7 @@ test("Transform type transfer", () => { transaction: { account_id: "AG7EkLW7DRSVaN8Z75jMT1DJN51QpWc9LKB7w", account_owner: null, - amount: 5.4, + amount: 31.53, authorized_date: "2024-02-23", authorized_datetime: null, category: ["Travel", "Taxi"], diff --git a/apps/engine/src/providers/plaid/transform.ts b/apps/engine/src/providers/plaid/transform.ts index a010fb1a58..d03e3e3661 100644 --- a/apps/engine/src/providers/plaid/transform.ts +++ b/apps/engine/src/providers/plaid/transform.ts @@ -159,7 +159,7 @@ export const transformTransaction = ({ description: transformDescription(transaction), method, internal_id: transaction.transaction_id, - amount: formatAmout(amount), + amount, currency: transaction.iso_currency_code || transaction.unofficial_currency_code ||