1 import TaxReturn from '../TaxReturn';
2 import Person from '../Person';
4 import Form1040, { FilingStatus } from './Form1040';
5 import Form1099B, { GainType } from './Form1099B';
6 import Form8949, { Form8949Box, Form8949Total } from './Form8949';
8 describe('single form', () => {
9 for (const box of [Form8949Box.A, Form8949Box.B, Form8949Box.D, Form8949Box.E]) {
10 test(`box ${Form8949Box[box]}`, () => {
11 const p = Person.self('A');
12 const tr = new TaxReturn(2019);
13 tr.addForm(new Form1040({ filingStatus: FilingStatus.Single }));
14 tr.addForm(new Form1099B({
17 description: '10 shares',
20 gainType: (box == Form8949Box.A || box == Form8949Box.B) ? GainType.ShortTerm : GainType.LongTerm,
21 basisReportedToIRS: (box == Form8949Box.A || box == Form8949Box.D),
24 const form = new Form8949();
27 const allBoxes: (keyof Form8949['lines'])[] = ['boxA', 'boxB', 'boxC', 'boxD', 'boxE', 'boxF'];
28 const otherBoxes = allBoxes.filter(b => b != `box${box}`);
29 const thisBox = `box${box}` as keyof Form8949['lines'];
31 let total = form.getValue(tr, thisBox);
33 expect(total.proceeds).toBe(100);
34 expect(total.costBasis).toBe(110);
35 expect(total.adjustments).toBe(0);
36 expect(total.gainOrLoss).toBe(-10);
38 for (let otherBox of otherBoxes) {
39 total = form.getValue(tr, otherBox);
40 expect(total.proceeds).toBe(0);
41 expect(total.costBasis).toBe(0);
42 expect(total.adjustments).toBe(0);
43 expect(total.gainOrLoss).toBe(0);
49 test('multiple forms', () => {
50 const p = Person.self('A');
51 const tr = new TaxReturn(2019);
52 tr.addForm(new Form1040({ filingStatus: FilingStatus.Single }));
53 tr.addForm(new Form1099B({
56 description: '10 SCHB',
59 gainType: GainType.ShortTerm,
60 basisReportedToIRS: true,
62 tr.addForm(new Form1099B({
65 description: '10 SCHB',
68 gainType: GainType.LongTerm,
69 basisReportedToIRS: false,
71 tr.addForm(new Form1099B({
74 description: '10 SCHF',
77 gainType: GainType.LongTerm,
78 basisReportedToIRS: false,
81 const form = new Form8949();
84 const boxA = form.getValue(tr, 'boxA');
85 expect(boxA.proceeds).toBe(55);
86 expect(boxA.costBasis).toBe(50);
87 expect(boxA.adjustments).toBe(0);
88 expect(boxA.gainOrLoss).toBe(5);
90 const boxE = form.getValue(tr, 'boxE');
91 expect(boxE.proceeds).toBe(77.40);
92 expect(boxE.costBasis).toBe(60.10);
93 expect(boxE.adjustments).toBe(0);
94 expect(boxE.gainOrLoss).toBeCloseTo(17.3);
96 const otherBoxes: (keyof Form8949['lines'])[] = ['boxB', 'boxC', 'boxD', 'boxF'];
97 for (const otherBox of otherBoxes) {
98 const other = form.getValue(tr, otherBox);
99 expect(other.proceeds).toBe(0);
100 expect(other.costBasis).toBe(0);
101 expect(other.adjustments).toBe(0);
102 expect(other.gainOrLoss).toBe(0);
106 test('adjustments', () => {
107 const p = Person.self('A');
108 const tr = new TaxReturn(2019);
109 tr.addForm(new Form1040({ filingStatus: FilingStatus.Single }));
110 const b1 = new Form1099B({
113 description: '10 SCHB',
116 gainType: GainType.ShortTerm,
117 basisReportedToIRS: false,
120 const b2 = new Form1099B({
123 description: '10 SCHB',
126 gainType: GainType.LongTerm,
127 basisReportedToIRS: false,
130 tr.addForm(new Form1099B({
133 description: '10 SCHF',
136 gainType: GainType.LongTerm,
137 basisReportedToIRS: true,
140 const form = new Form8949({
142 { entry: b1, code: 'W', amount: -10 },
143 { entry: b2, code: 'W', amount: 90 },
148 const boxB = form.getValue(tr, 'boxB');
149 expect(boxB.proceeds).toBe(55);
150 expect(boxB.costBasis).toBe(50);
151 expect(boxB.adjustments).toBe(-10);
152 expect(boxB.gainOrLoss).toBe(-5);
154 const boxE = form.getValue(tr, 'boxE');
155 expect(boxE.proceeds).toBe(18);
156 expect(boxE.costBasis).toBe(25);
157 expect(boxE.adjustments).toBe(90);
158 expect(boxE.gainOrLoss).toBe(83);
160 const boxD = form.getValue(tr, 'boxD');
161 expect(boxD.proceeds).toBe(22.40);
162 expect(boxD.costBasis).toBe(10.10);
163 expect(boxD.adjustments).toBe(0);
164 expect(boxD.gainOrLoss).toBeCloseTo(12.30);
166 const otherBoxes: (keyof Form8949['lines'])[] = ['boxA', 'boxC', 'boxF'];
167 for (const otherBox of otherBoxes) {
168 const other = form.getValue(tr, otherBox);
169 expect(other.proceeds).toBe(0);
170 expect(other.costBasis).toBe(0);
171 expect(other.adjustments).toBe(0);
172 expect(other.gainOrLoss).toBe(0);