Remove type test code for TaxReturn.
[ustaxlib.git] / src / core / TaxReturn.test.ts
1 import TaxReturn from './TaxReturn';
2 import Person from './Person';
3 import Form 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<null> {
57 readonly name = 'Test Form';
58 protected readonly _lines = null;
59 };
60
61 const tr = new TaxReturn(2019);
62 const f = new TestForm();
63 tr.addForm(f);
64 expect(() => tr.addForm(new TestForm)).toThrow(InconsistencyError);
65 expect(tr.getForm(TestForm)).toBe(f);
66 expect(tr.findForm(TestForm)).toBe(f);
67 });
68
69 test('multiple-copy forms', () => {
70 class TestForm extends Form<null> {
71 readonly name = 'Test Form';
72 readonly supportsMultipleCopies = true;
73 protected readonly _lines = null;
74 };
75
76 const tr = new TaxReturn(2019);
77 const f1 = new TestForm();
78 const f2 = new TestForm();
79 const f3 = new TestForm();
80 tr.addForm(f1);
81 tr.addForm(f2);
82
83 expect(() => tr.getForm(TestForm)).toThrow(InconsistencyError);
84 expect(() => tr.findForm(TestForm)).toThrow(InconsistencyError);
85
86 const forms = tr.findForms(TestForm);
87 expect(forms.length).toBe(2);
88 expect(forms).toContain(f1);
89 expect(forms).toContain(f2);
90 expect(forms).not.toContain(f3);
91 });
92
93 test('get non-existent form', () => {
94 class TestForm extends Form<null> {
95 readonly name = 'Test Form';
96 protected readonly _lines = null;
97 }
98 const tr = new TaxReturn(2019);
99 expect(() => tr.getForm(TestForm)).toThrow(NotFoundError);
100 expect(tr.findForm(TestForm)).toBeNull();
101 expect(tr.findForms(TestForm)).toEqual([]);
102 });