File size: 9,590 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import { expect, test } from "bun:test";
import {
  transformAccount,
  transformAccountBalance,
  transformTransaction,
} from "./transform";

test("Transform pending transaction", () => {
  expect(
    transformTransaction({
      accountType: "depository",
      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",
        },
        description: "Online Check Deposit",
        date: "2024-03-05",
        amount: "-83.62",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform credit card purchase transaction", () => {
  expect(
    transformTransaction({
      accountType: "credit",
      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",
        },
        description: "Technology",
        date: "2024-03-05",
        amount: "29",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform credit card payment received - should be credit-card-payment not income", () => {
  // When paying off a credit card, Teller reports negative amount (money coming IN to card)
  // This should NOT be categorized as income - it's a credit card payment
  expect(
    transformTransaction({
      accountType: "credit",
      transaction: {
        type: "payment",
        status: "posted",
        running_balance: "500.00",
        links: {
          self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl3000",
          account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000",
        },
        id: "txn_os41r5u90e29shubl3000",
        details: {
          processing_status: "complete",
          counterparty: {
            type: "organization",
            name: "BANK PAYMENT",
          },
          category: "general",
        },
        description: "Payment Thank You",
        date: "2024-03-05",
        amount: "-200.00",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform credit card refund - should have no category", () => {
  // A refund on a credit card should not be auto-categorized
  expect(
    transformTransaction({
      accountType: "credit",
      transaction: {
        type: "card_payment", // refunds often come through as card_payment type
        status: "posted",
        running_balance: "500.00",
        links: {
          self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl4000",
          account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000",
        },
        id: "txn_os41r5u90e29shubl4000",
        details: {
          processing_status: "complete",
          counterparty: {
            type: "organization",
            name: "AMAZON REFUND",
          },
          category: "shopping",
        },
        description: "Amazon Refund",
        date: "2024-03-05",
        amount: "-50.00",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform credit card cashback - should be income", () => {
  // Cashback/rewards marked as income by Teller should stay as income
  expect(
    transformTransaction({
      accountType: "credit",
      transaction: {
        type: "other",
        status: "posted",
        running_balance: "500.00",
        links: {
          self: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000/transactions/txn_os41r5u90e29shubl5000",
          account: "https://api.teller.io/accounts/acc_os41qe3a66ks2djhss000",
        },
        id: "txn_os41r5u90e29shubl5000",
        details: {
          processing_status: "complete",
          counterparty: {
            type: "organization",
            name: "REWARDS",
          },
          category: "income",
        },
        description: "Cash Back Rewards",
        date: "2024-03-05",
        amount: "-25.00",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform card payment transaction", () => {
  expect(
    transformTransaction({
      accountType: "depository",
      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",
        },
        description: "Nordstrom",
        date: "2024-03-01",
        amount: "-68.90",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform income transaction", () => {
  expect(
    transformTransaction({
      accountType: "depository",
      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",
        },
        description: "Exxon Mobil",
        date: "2024-03-03",
        amount: "1000000",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform type transfer", () => {
  expect(
    transformTransaction({
      accountType: "depository",
      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",
        },
        description: "Recurring Transfer to Savings",
        date: "2024-01-27",
        amount: "-37.99",
        account_id: "acc_os41qe3a66ks2djhss000",
      },
    }),
  ).toMatchSnapshot();
});

test("Transform accounts", () => {
  expect(
    transformAccount({
      type: "credit",
      subtype: "credit_card",
      status: "open",
      name: "Platinum Card",
      links: {
        transactions:
          "https://api.teller.io/accounts/acc_os557c2mge29shubl2000/transactions",
        self: "https://api.teller.io/accounts/acc_os557c2mge29shubl2000",
        balances:
          "https://api.teller.io/accounts/acc_os557c2mge29shubl2000/balances",
      },
      last_four: "6587",
      institution: {
        name: "Mercury",
        id: "mercury",
      },
      balance: {
        currency: "USD",
        amount: 2011100,
        available_balance: null,
        credit_limit: null,
      },
      id: "acc_os557c2mge29shubl2000",
      enrollment_id: "enr_os557c8pck2deoskak000",
      currency: "USD",
    }),
  ).toMatchSnapshot();
});

test("Transform account balance - depository", () => {
  expect(
    transformAccountBalance({
      balance: {
        currency: "USD",
        amount: 2011100,
      },
      accountType: "depository",
    }),
  ).toMatchSnapshot();
});

test("Transform account balance - credit with positive (stays positive)", () => {
  // Teller returns positive values for credit card debt
  expect(
    transformAccountBalance({
      balance: {
        currency: "USD",
        amount: 150000,
      },
      accountType: "credit",
    }),
  ).toEqual({
    currency: "USD",
    amount: 150000,
    available_balance: null,
    credit_limit: null,
  });
});

test("Transform account balance - credit with negative (normalized to positive)", () => {
  // Safety: if Teller ever returns negative credit balance, normalize it
  expect(
    transformAccountBalance({
      balance: {
        currency: "USD",
        amount: -150000,
      },
      accountType: "credit",
    }),
  ).toEqual({
    currency: "USD",
    amount: 150000,
    available_balance: null,
    credit_limit: null,
  });
});