Skip to content

Commit

Permalink
Feat/better stats message (#341)
Browse files Browse the repository at this point in the history
* Map NIS to ILS

* Move all SaveStat code to a single place

* Send info on foreign transactions

* [autofix.ci] apply automated fixes

* Created `foreignTransactionsSummary`

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
daniel-hauser and autofix-ci[bot] authored Sep 8, 2024
1 parent 2bc0935 commit b433fd0
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 243 deletions.
15 changes: 8 additions & 7 deletions src/__snapshots__/messages.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ exports[`messages getSummaryMessages should not add empty groups 2`] = `
`;

exports[`messages getSummaryMessages should return a summary message 1`] = `
"7 transactions scraped.
(3 pending, 4 completed)
"8 transactions scraped.
(3 pending, 5 completed)
From completed, 3 not originally in ILS and 1 not charged in ILS
Accounts updated:
✔️ [max] account1: 1
✔️ [max] account2: 6
✔️ [max] account2: 7
Pending txns:
description1: +20.00
Expand All @@ -36,11 +37,11 @@ Pending txns:
exports[`messages getSummaryMessages should return a summary message 2`] = `
[
"📝 Storage 1 (TheTable)
2 added
4 skipped (5 existing, 3 pending)",
1 added
0 skipped (0 existing, 0 pending)",
"📝 Storage 2 (TheTable)
7 added
9 skipped (10 existing, 8 pending)
0 skipped (0 existing, 3 pending)
-----
Group1:
description1: +10.00",
Expand Down Expand Up @@ -78,7 +79,7 @@ exports[`messages getSummaryMessages should return a summary message with instal
[
"📝 Storage 1 (TheTable)
2 added
4 skipped (5 existing, 3 pending)
0 skipped (0 existing, 0 pending)
-----
SomeGroup:
should be +20: +20.00
Expand Down
169 changes: 75 additions & 94 deletions src/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
import { CompanyTypes } from "israeli-bank-scrapers";
import { getSummaryMessages, saved } from "./messages";
import {
AccountScrapeResult,
SaveStats,
Transaction,
TransactionRow,
} from "./types";
import { getSummaryMessages } from "./messages";
import { AccountScrapeResult, Transaction, TransactionRow } from "./types";
import {
TransactionStatuses,
TransactionTypes,
} from "israeli-bank-scrapers/lib/transactions";
import { ScraperErrorTypes } from "israeli-bank-scrapers/lib/scrapers/errors";
import { createSaveStats, SaveStats, statsString } from "./saveStats";

describe("messages", () => {
describe("getSummaryMessages", () => {
it("should return a summary message", () => {
const txns1 = [
transaction({
chargedAmount: -20,
originalAmount: -100,
description: "ILS",
chargedCurrency: "ILS",
originalCurrency: "USD",
}),
];

const txns2 = [
transaction({
type: TransactionTypes.Installments,
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: 20,
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: 20,
originalCurrency: "USD",
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: -20,
}),
transaction({
description: "description2",
memo: "memo2",
}),
transaction({
chargedAmount: 20,
originalAmount: 5,
originalCurrency: "USD",
}),
transaction({
chargedAmount: 1000,
originalAmount: 1000,
originalCurrency: "USD",
chargedCurrency: "USD",
}),
];
const results: Array<AccountScrapeResult> = [
{
companyId: CompanyTypes.max,
Expand All @@ -23,69 +62,23 @@ describe("messages", () => {
accounts: [
{
accountNumber: "account1",
txns: [
transaction({
chargedAmount: -20,
originalAmount: -100,
description: "ILS",
chargedCurrency: "ILS",
originalCurrency: "USD",
}),
],
txns: txns1,
},
{
accountNumber: "account2",
txns: [
transaction({
type: TransactionTypes.Installments,
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: 20,
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: 20,
originalCurrency: "USD",
}),
transaction({
status: TransactionStatuses.Pending,
originalAmount: -20,
}),
transaction({
description: "description2",
memo: "memo2",
}),
transaction({
chargedAmount: 20,
originalAmount: 5,
originalCurrency: "USD",
}),
],
txns: txns2,
},
],
},
},
];

const stats: Array<SaveStats> = [
{
name: "Storage 1",
table: "TheTable",
total: 1,
added: 2,
pending: 3,
skipped: 4,
existing: 5,
},
{
name: "Storage 2",
table: "TheTable",
total: 6,
added: 7,
pending: 8,
skipped: 9,
existing: 10,
createSaveStats("Storage 1", "TheTable", txns1 as any, {
added: txns1.length,
}),
createSaveStats("Storage 2", "TheTable", txns2 as any, {
added: txns2.length,
highlightedTransactions: {
Group1: [
{
Expand All @@ -104,13 +97,13 @@ describe("messages", () => {
},
],
},
},
}),
];

const summary = getSummaryMessages(results);
expect(summary).toMatchSnapshot();

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});

Expand All @@ -122,7 +115,7 @@ describe("messages", () => {
const summary = getSummaryMessages(results);
expect(summary).toMatchSnapshot();

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});

Expand Down Expand Up @@ -162,7 +155,7 @@ describe("messages", () => {
const summary = getSummaryMessages(results);
expect(summary).toMatchSnapshot();

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});

Expand Down Expand Up @@ -198,14 +191,8 @@ describe("messages", () => {
];

const stats: Array<SaveStats> = [
{
name: "Storage 1",
table: "TheTable",
total: 1,
createSaveStats("Storage 1", "TheTable", transactions as any, {
added: 2,
pending: 3,
skipped: 4,
existing: 5,
highlightedTransactions: {
SomeGroup: transactions.map<TransactionRow>((t) => ({
account: "account1",
Expand All @@ -215,26 +202,26 @@ describe("messages", () => {
...t,
})),
},
},
}),
];

const summary = getSummaryMessages(results);
expect(summary).toMatchSnapshot();

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});

it("should not add empty groups", () => {
const tx = {
...transaction({}),
hash: "hash1",
uniqueId: "uniqueId1",
account: "account1",
companyId: CompanyTypes.max,
};
const stats: Array<SaveStats> = [
{
name: "Storage",
table: "TheTable",
total: 1,
added: 0,
pending: 0,
skipped: 0,
existing: 0,
createSaveStats("Storage", "TheTable", [tx], {
highlightedTransactions: {
Group1: [],
Group2: [
Expand All @@ -247,43 +234,37 @@ describe("messages", () => {
},
],
},
},
}),
];

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});

it("should not add empty groups", () => {
const stats: Array<SaveStats> = [
{
name: "Storage",
table: "TheTable",
total: 1,
added: 0,
pending: 0,
skipped: 0,
existing: 0,
createSaveStats("Storage", "TheTable", [], {
highlightedTransactions: {
Group1: [],
},
},
}),
];

const saveSummaries = stats.map(saved);
const saveSummaries = stats.map(statsString);
expect(saveSummaries).toMatchSnapshot();
});
});
});

function transaction(t: Partial<Transaction>): Transaction {
export function transaction(t: Partial<Transaction>): Transaction {
return {
type: TransactionTypes.Normal,
date: new Date().toISOString(),
processedDate: new Date().toISOString(),
description: "description1",
originalAmount: 10,
originalCurrency: "ILS",
chargedCurrency: "ILS",
chargedAmount: t.status === TransactionStatuses.Pending ? 0 : 10,
status: TransactionStatuses.Completed,
...t,
Expand Down
Loading

0 comments on commit b433fd0

Please sign in to comment.