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