Redo 1099-B to be simplerf for recording adjustments.
[ustaxlib.git] / src / fed2019 / Form1116.test.ts
1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
5
6 import { Person } from '../core';
7 import { UnsupportedFeatureError } from '../core/Errors';
8
9 import Form1040, { FilingStatus } from './Form1040';
10 import Form1116, { ForeignIncomeCategory } from './Form1116';
11 import Form1099B from './Form1099B';
12 import Form1099DIV from './Form1099DIV';
13 import Form8949 from './Form8949';
14 import W2 from './W2';
15 import TaxReturn from './TaxReturn';
16 import ScheduleD from './ScheduleD';
17
18 test('supported income category', () => {
19 const p = Person.self('A');
20 const tr = new TaxReturn();
21 const f = new Form1116({
22 person: p,
23 incomeCategory: ForeignIncomeCategory.C,
24 posessionName: "RIC",
25 grossForeignIncome: 100,
26 totalForeignTaxesPaidOrAccrued: 0
27 });
28 tr.addForm(f);
29 expect(f.getValue(tr, 'category')).toBe(ForeignIncomeCategory.C);
30 });
31
32 test('unsupported income categories', () => {
33 for (const category of Object.values(ForeignIncomeCategory)) {
34 if (category == ForeignIncomeCategory.C)
35 continue;
36
37 const p = Person.self('B');
38 const tr = new TaxReturn();
39 const f = new Form1116({
40 person: p,
41 incomeCategory: category,
42 posessionName: "RIC",
43 grossForeignIncome: 100,
44 totalForeignTaxesPaidOrAccrued: 0
45 });
46 tr.addForm(f);
47 expect(() => f.getValue(tr, 'category')).toThrow(UnsupportedFeatureError);
48 }
49 });
50
51 test('foreign tax credit', () => {
52 const tr = new TaxReturn();
53 const p = Person.self('A');
54 tr.addPerson(p);
55 tr.addForm(new Form1040({
56 filingStatus: FilingStatus.MarriedFilingJoint
57 }));
58 tr.addForm(new W2({
59 employer: 'ACME',
60 employee: p,
61 wages: 697000,
62 }));
63
64 const f = new Form1116({
65 person: p,
66 incomeCategory: ForeignIncomeCategory.C,
67 posessionName: "RIC",
68 grossForeignIncome: 99,
69 totalForeignTaxesPaidOrAccrued: 14
70 });
71 tr.addForm(f);
72
73 expect(f.getValue(tr, '1a')).toBe(99);
74 expect(f.getValue(tr, '3a')).toBe(24400);
75 expect(f.getValue(tr, '3c')).toBe(24400);
76 expect(f.getValue(tr, '3d')).toBe(99);
77 expect(f.getValue(tr, '3e')).toBe(697000);
78 expect(f.getValue(tr, '3f')).toBe(0.0001);
79 expect(f.getValue(tr, '3g')).toBeCloseTo(2.44);
80 expect(f.getValue(tr, '6')).toBeCloseTo(2.44);
81 expect(f.getValue(tr, '7')).toBeCloseTo(96.56);
82 expect(f.getValue(tr, '8')).toBe(14);
83 expect(f.getValue(tr, '9')).toBe(14);
84 expect(f.getValue(tr, '14')).toBe(14);
85 expect(f.getValue(tr, '20')).toBe(((697000-24400) * 0.37) - 61860);
86 expect(f.getValue(tr, '21')).toBeCloseTo(26.846);
87 expect(f.getValue(tr, '22')).toBe(14);
88 expect(f.getValue(tr, '31')).toBe(14);
89 expect(f.getValue(tr, '33')).toBe(14);
90 });
91
92 test('no net capital losses in total income', () => {
93 const p = Person.self('A');
94 const tr = new TaxReturn();
95 tr.addPerson(p);
96 tr.addForm(new Form1040({
97 filingStatus: FilingStatus.MarriedFilingJoint
98 }));
99 tr.addForm(new W2({
100 employer: 'Megacorp',
101 employee: p,
102 wages: 200000
103 }));
104 tr.addForm(new Form1099B({
105 payer: 'Brokerage',
106 payee: p,
107 longTermBasisReported: [
108 {
109 description: 'SCHF',
110 proceeds: 100,
111 costBasis: 50,
112 }
113 ],
114 shortTermBasisReported: [
115 {
116 description: 'SCHE',
117 proceeds: 60,
118 costBasis: 100,
119 }
120 ]
121 }));
122 tr.addForm(new Form8949);
123 tr.addForm(new ScheduleD);
124
125 const f = new Form1116({
126 person: p,
127 incomeCategory: ForeignIncomeCategory.C,
128 posessionName: 'RIC',
129 grossForeignIncome: 200,
130 totalForeignTaxesPaidOrAccrued: 65
131 });
132
133 expect(tr.getForm(Form8949).getValue(tr, 'boxA').gainOrLoss).toBe(-40);
134 expect(tr.getForm(Form8949).getValue(tr, 'boxD').gainOrLoss).toBe(50);
135 expect(f.getValue(tr, '3e')).toBe(200050);
136 });