Skip to content

Commit

Permalink
fix: confirmation modal does not change the transaction in the edit f…
Browse files Browse the repository at this point in the history
…ields
  • Loading branch information
kajyr committed Dec 16, 2021
1 parent bbfda57 commit 98e7202
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
35 changes: 35 additions & 0 deletions frontend/src/pages/dashboard/prepare-submit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Posting } from 'pta-tools';

import prepareSubmit from './prepare-submit';

import { FormData, OPTION_SPLITWISE } from './';

describe("prepareSubmit", () => {
test("Does not mutate the input trx", () => {
const trx: FormData = {
comment: "comment",
date: new Date("2019-01-01"),
description: "string",
entries: [{ account: "Bar", amount: "7" }],
payingAccount: "Cash",
};

expect(prepareSubmit(trx, []).entries.length).toBe(2);
expect(trx.entries.length).toBe(1); // trx.entries is not mutated
});
test("Splits with Splitwise", () => {
const trx: FormData = {
comment: "comment",
date: new Date("2019-01-01"),
description: "string",
entries: [{ account: "Bar", amount: "7" }],
payingAccount: "Cash",
};

const result = prepareSubmit(trx, [OPTION_SPLITWISE]);
expect(result.entries.length).toBe(3);
expect((result.entries[0] as Posting).amount).toBe("3.5");
expect((result.entries[1] as Posting).amount).toBe("3.5");
expect((result.entries[2] as Posting).account).toBe("Cash");
});
});
4 changes: 3 additions & 1 deletion frontend/src/pages/dashboard/prepare-submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function prepareSubmitData(data: FormData, options: string[]): Transaction {
}

if (payingAccount) {
transaction.entries.push({ account: payingAccount });
transaction.entries = transaction.entries.concat({
account: payingAccount,
});
}
return transaction;
}
Expand Down

0 comments on commit 98e7202

Please sign in to comment.