Make Person the default export.
[ustaxlib.git] / src / TaxReturn.test.ts
1 import TaxReturn from './TaxReturn';
2 import Person from './Person';
3 import Form, { SupportsMultipleCopies } from './Form';
4 import { NotFoundError, InconsistencyError } from './Errors';
5
6 test('constructor', () => {
7 const tr = new TaxReturn(2019);
8 expect(tr.year).toBe(2019);
9 });
10
11 test('does not support Dependents', () => {
12 const tr = new TaxReturn(2019);
13 const p = Person.dependent('Baby');
14 expect(() => tr.addPerson(p)).toThrow('Dependents are not supported');
15 });
16
17 test('add more than one Self', () => {
18 const tr = new TaxReturn(2019);
19 const p1 = Person.self('A');
20 tr.addPerson(p1);
21 const p2 = Person.self('B');
22 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
23 });
24
25 test('add more than one Spouse', () => {
26 const tr = new TaxReturn(2019);
27 const p1 = Person.spouse('A');
28 tr.addPerson(p1);
29 const p2 = Person.spouse('B');
30 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
31 });
32
33 test('add Self and Spouse', () => {
34 const tr = new TaxReturn(2019);
35 const self = Person.self('Billy Bob');
36 const spouse = Person.spouse('Jilly Bob');
37 tr.addPerson(self);
38 tr.addPerson(spouse);
39
40 expect(tr.getPerson('Billy')).toBe(self);
41 expect(tr.getPerson('Jilly')).toBe(spouse);
42
43 expect(() => tr.getPerson('Bob')).toThrow('too imprecise');
44 });
45
46 test('get non-existent person', () => {
47 const tr = new TaxReturn(2019);
48 const self = Person.self('Billy Bob');
49 tr.addPerson(self);
50
51 expect(tr.getPerson('Billy Bob')).toBe(self);
52 expect(() => tr.getPerson('Jilly')).toThrow('not found');
53 });
54
55 test('single-copy forms', () => {
56 class TestForm extends Form {
57 get name(): string { return 'Test Form'; }
58
59 protected getLines() { return []; }
60 };
61
62 const tr = new TaxReturn(2019);
63 const f = new TestForm();
64 tr.addForm(f);
65 expect(() => tr.addForm(new TestForm)).toThrow(InconsistencyError);
66 expect(tr.getForm(f.name)).toBe(f);
67 });
68
69 test('multiple-copy forms', () => {
70 class TestForm extends Form implements SupportsMultipleCopies {
71 get name(): string { return 'Test Form'; }
72
73 aggregate(forms: Form[]): this { return null; }
74
75 protected getLines() { return []; }
76 };
77
78 const tr = new TaxReturn(2019);
79 const f1 = new TestForm();
80 const f2 = new TestForm();
81 const f3 = new TestForm();
82 tr.addForm(f1);
83 tr.addForm(f2);
84
85 expect(() => tr.getForm(f1.name)).toThrow(InconsistencyError);
86
87 const forms = tr.getForms(f1.name);
88 expect(forms.length).toBe(2);
89 expect(forms).toContain(f1);
90 expect(forms).toContain(f2);
91 expect(forms).not.toContain(f3);
92 });
93
94 test('get non-existent form', () => {
95 const tr = new TaxReturn(2019);
96 expect(() => tr.getForm('form')).toThrow(NotFoundError);
97 expect(tr.getForms('form')).toEqual([]);
98 });