Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Dresden committed Apr 12, 2024
1 parent b1020c2 commit 28e74dd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
Expand All @@ -16,6 +16,8 @@ import { ScheduleDTransactionTypes } from 'app/shared/models/schd-transaction.mo
import { ReportTypes } from 'app/shared/models/report.model';
import { Form24 } from 'app/shared/models/form-24.model';
import { ScheduleETransactionGroups } from 'app/shared/models/sche-transaction.model';
import { isPAC, isPTY } from 'app/shared/models/committee-account.model';
import { ScheduleATransactionGroups, ScheduleATransactionTypes } from 'app/shared/models/scha-transaction.model';

describe('TransactionTypePickerComponent', () => {
let component: TransactionTypePickerComponent;
Expand All @@ -39,6 +41,7 @@ describe('TransactionTypePickerComponent', () => {
params: of({
catalog: 'receipt',
}),
queryParamMap: of({ get: (key: string) => (key === 'param1' ? 'value1' : undefined) }),
},
},
provideMockStore(testMockStore),
Expand Down Expand Up @@ -96,4 +99,30 @@ describe('TransactionTypePickerComponent', () => {
component.category = 'loans-and-debts';
expect(component.getCategoryTitle()).toEqual('Add loans and debts');
});

it('should get committee account', fakeAsync(() => {
component.ngOnInit();
tick(500);
expect(component.committeeAccount).toBeTruthy();
}));

describe('getTransactionTypes', () => {
it('should limit by PACRestricted if Committee type is PAC', fakeAsync(() => {
component.ngOnInit();
tick(500);
if (component.committeeAccount) component.committeeAccount.committee_type = 'O';
expect(isPAC(component.committeeAccount?.committee_type)).toBeTrue();
const types = component.getTransactionTypes(ScheduleATransactionGroups.TRANSFERS);
expect(types.includes(ScheduleATransactionTypes.IN_KIND_TRANSFER_FEDERAL_ELECTION_ACTIVITY)).toBeFalse();
}));

it('should limit by PTYRestricted if Committee type is PTY', fakeAsync(() => {
component.ngOnInit();
tick(500);
if (component.committeeAccount) component.committeeAccount.committee_type = 'X';
expect(isPTY(component.committeeAccount?.committee_type)).toBeTrue();
const types = component.getTransactionTypes(ScheduleATransactionGroups.OTHER);
expect(types.includes(ScheduleATransactionTypes.INDIVIDUAL_RECEIPT_NON_CONTRIBUTION_ACCOUNT)).toBeFalse();
}));
});
});
23 changes: 23 additions & 0 deletions front-end/src/app/shared/models/committee-member.model.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { isPAC, isPTY } from './committee-account.model';
import { CommitteeMember } from './committee-member.model';

describe('CommitteeMember', () => {
it('should create an instance', () => {
expect(new CommitteeMember()).toBeTruthy();
});

it('should be created correctly from JSON', () => {
const json = {
role: 'COMMITTEE_ADMINISTRATOR',
Expand All @@ -19,17 +21,38 @@ describe('CommitteeMember', () => {
expect(member.role).toBe(json['role']);
expect(member.is_active).toBe(json['is_active']);
});

it('should return the correct role label when role is not null', () => {
const member = new CommitteeMember();
member.role = 'COMMITTEE_ADMINISTRATOR';
expect(member.getRoleLabel()).toBe('Committee Administrator');
});

it('should return an empty string for a role label if role is null', () => {
expect(new CommitteeMember().getRoleLabel()).toBe('');
});

it('should return an empty string for a label if the role is not present in the LabelList', () => {
const cUser = new CommitteeMember();
cUser.role = "This Isn't a Real Role";
expect(cUser.getRoleLabel()).toBe('');
});

it('should confirm if committee is PAC', () => {
expect(isPAC()).toBeFalse();
const PAC = ['O', 'U', 'D', 'N', 'Q', 'V', 'W'];
PAC.forEach((entry) => {
expect(isPAC(entry)).toBeTrue();
});
expect(isPAC('X')).toBeFalse();
});

it('should confirm if committee is PTY', () => {
expect(isPTY()).toBeFalse();
const PTY = ['X', 'Y'];
PTY.forEach((entry) => {
expect(isPTY(entry)).toBeTrue();
});
expect(isPTY('O')).toBeFalse();
});
});
23 changes: 22 additions & 1 deletion front-end/src/app/shared/utils/transaction-type.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TransactionTypeUtils, getFromJSON } from './transaction-type.utils';
import { ScheduleATransactionTypes } from '../models/scha-transaction.model';
import { PACRestricted, PTYRestricted, TransactionTypeUtils, getFromJSON } from './transaction-type.utils';

describe('LabelUtils', () => {
it('should create an instance', () => {
Expand Down Expand Up @@ -27,4 +28,24 @@ describe('LabelUtils', () => {
scheduleObject = getFromJSON(testJSON);
expect(scheduleObject.constructor.name).toBe('SchETransaction');
});

it('should return list of Transaction Types PAC does not need access to', () => {
[
ScheduleATransactionTypes.IN_KIND_TRANSFER_FEDERAL_ELECTION_ACTIVITY,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_CONVENTION_ACCOUNT,
].forEach((r) => {
expect(PACRestricted().includes(r));
});
});

it('should return list of Transaction Types PTY does not need access to', () => {
[
ScheduleATransactionTypes.INDIVIDUAL_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.OTHER_COMMITTEE_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.BUSINESS_LABOR_NON_CONTRIBUTION_ACCOUNT,
].forEach((r) => {
expect(PTYRestricted().includes(r));
});
});
});

0 comments on commit 28e74dd

Please sign in to comment.