1 import TaxReturn from './TaxReturn';
2 import { Person } from './Person';
3 import Form, { SupportsMultipleCopies } from './Form';
4 import { NotFoundError, InconsistencyError } from './Errors';
6 test('constructor', () => {
7 const tr = new TaxReturn(2019);
8 expect(tr.year).toBe(2019);
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');
17 test('add more than one Self', () => {
18 const tr = new TaxReturn(2019);
19 const p1 = Person.self('A');
21 const p2 = Person.self('B');
22 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
25 test('add more than one Spouse', () => {
26 const tr = new TaxReturn(2019);
27 const p1 = Person.spouse('A');
29 const p2 = Person.spouse('B');
30 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
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');
40 expect(tr.getPerson('Billy')).toBe(self);
41 expect(tr.getPerson('Jilly')).toBe(spouse);
43 expect(() => tr.getPerson('Bob')).toThrow('too imprecise');
46 test('get non-existent person', () => {
47 const tr = new TaxReturn(2019);
48 const self = Person.self('Billy Bob');
51 expect(tr.getPerson('Billy Bob')).toBe(self);
52 expect(() => tr.getPerson('Jilly')).toThrow('not found');
55 test('single-copy forms', () => {
56 class TestForm extends Form {
57 get name(): string { return 'Test Form'; }
59 protected getLines() { return []; }
62 const tr = new TaxReturn(2019);
63 const f = new TestForm();
65 expect(() => tr.addForm(new TestForm)).toThrow(InconsistencyError);
66 expect(tr.getForm(f.name)).toBe(f);
69 test('multiple-copy forms', () => {
70 class TestForm extends Form implements SupportsMultipleCopies {
71 get name(): string { return 'Test Form'; }
73 aggregate(forms: Form[]): this { return null; }
75 protected getLines() { return []; }
78 const tr = new TaxReturn(2019);
79 const f1 = new TestForm();
80 const f2 = new TestForm();
81 const f3 = new TestForm();
85 expect(() => tr.getForm(f1.name)).toThrow(InconsistencyError);
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);
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([]);