Skip to content

Commit

Permalink
Merge pull request #1036 from knod/code-style-12
Browse files Browse the repository at this point in the history
Cleans '/src/programs'. #1018
  • Loading branch information
knod authored Dec 5, 2018
2 parents 9c3a15d + c697f07 commit 70bd223
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 89 deletions.
62 changes: 31 additions & 31 deletions src/programs/federal/snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const getSNAPBenefits = function (fullClient, timeframe) {

let client = fullClient[ timeframe ];

let finalResult = 0,
householdSize = hlp.getHouseholdSize(client),
grossIncomeTestResult = hlp.passesGrossIncomeTest(client),
netIncomeTestResult = hlp.passesNetIncomeTest(client),
maxSnapAllotment = getLimitBySize(SNAPData.SNAP_LIMITS, householdSize),
percentageOfNetIncome = hlp.getNetIncome(client) * SNAPData.PERCENT_OF_NET,
maxClientAllotment = Math.max(0, maxSnapAllotment - percentageOfNetIncome);
let finalResult = 0,
householdSize = hlp.getHouseholdSize(client),
grossIncomeTestResult = hlp.passesGrossIncomeTest(client),
netIncomeTestResult = hlp.passesNetIncomeTest(client),
maxSnapAllotment = getLimitBySize(SNAPData.SNAP_LIMITS, householdSize),
percentageOfNetIncome = hlp.getNetIncome(client) * SNAPData.PERCENT_OF_NET,
maxClientAllotment = Math.max(0, maxSnapAllotment - percentageOfNetIncome);

if (grossIncomeTestResult === true && netIncomeTestResult === true) {

Expand Down Expand Up @@ -123,7 +123,6 @@ hlp.passesNetIncomeTest = function(client) {
} else {
return false;
}

};

// Used by 1 function. Easier unit tests
Expand Down Expand Up @@ -173,11 +172,11 @@ hlp.getNetIncome = function(client) {
* @returns {number}
*/
hlp.getAdjustedGrossMinusDeductions = function (client) {
let adjustedGross = hlp.getAdjustedGross(client),
standardDeduction = hlp.getStandardDeduction(client),
earnedIncomeDeduction = hlp.getEarnedIncomeDeduction(client),
medicalDeduction = hlp.getMedicalDeduction(client),
dependentCareDeduction = hlp.getDependentCareDeduction(client);
let adjustedGross = hlp.getAdjustedGross(client),
standardDeduction = hlp.getStandardDeduction(client),
earnedIncomeDeduction = hlp.getEarnedIncomeDeduction(client),
medicalDeduction = hlp.getMedicalDeduction(client),
dependentCareDeduction = hlp.getDependentCareDeduction(client);

let adjustedIncome = adjustedGross - standardDeduction - earnedIncomeDeduction - medicalDeduction - dependentCareDeduction;
return Math.max(0, adjustedIncome);
Expand Down Expand Up @@ -215,21 +214,21 @@ hlp.getEarnedIncomeDeduction = function (client) {
* @returns {number}
*/
hlp.getMedicalDeduction = function (client) {
let medicalDeduce = 0;
let medicalDeduction = 0;

if (hlp.hasDisabledOrElderlyMember(client) === true) {
/** @todo Add disabledAssistance too. Also, otherMedical? */
let medicalExpenses = client.disabledMedical;
if ((medicalExpenses >= SNAPData.MIN_MEDICAL_EXPENSES) && (medicalExpenses <= SNAPData.MAX_MEDICAL_EXPENSES)) {
medicalDeduce = SNAPData.STANDARD_MEDICAL_DEDUCTION;
medicalDeduction = SNAPData.STANDARD_MEDICAL_DEDUCTION;

} else if (medicalExpenses >= SNAPData.MAX_MEDICAL_EXPENSES + 1) {
medicalDeduce = medicalExpenses - SNAPData.MIN_MEDICAL_EXPENSES;
medicalDeduction = medicalExpenses - SNAPData.MIN_MEDICAL_EXPENSES;

}
} // end if has disabled or elderly
} // ends if has disabled or elderly

return medicalDeduce;
return medicalDeduction;
};

// Used in 1 other function. Easier unit tests
Expand Down Expand Up @@ -269,8 +268,7 @@ hlp.getDependentCareDeduction = function (client) {
hlp.getHomelessDeduction = function(client) {
if (hlp.isHomeless(client)) {
return SNAPData.HOMELESS_DEDUCTION;
}
else {
} else {
return 0;
}
};
Expand All @@ -293,7 +291,6 @@ hlp.getShelterDeduction = function(client) {
} else {
return Math.min(rawDeduction, SNAPData.SHELTER_DEDUCTION_CAP);
}

};

// Used by 1 function. Easier unit tests
Expand Down Expand Up @@ -328,11 +325,11 @@ hlp.getNonUtilityHousingCosts = function(client) {

if (hlp.isHomeless(client)) {
housingCost = 0;
} else if (client.housing === 'homeowner') {
} else if (client.housing === `homeowner`) {
housingCost = client.mortgage + client.housingInsurance + client.propertyTax;
} else if (client.housing === 'renter') {
} else if (client.housing === `renter`) {
housingCost = client.rent;
} else if (client.housing === 'voucher') {
} else if (client.housing === `voucher`) {
housingCost = client.rentShare;
}

Expand All @@ -355,13 +352,13 @@ hlp.getUtilityCostByBracket = function (client) {
let utilityCategory = null;

if (client.climateControl || client.fuelAssistance) {
utilityCategory = 'Heating';
utilityCategory = `Heating`;
} else if (client.nonHeatElectricity) {
utilityCategory = 'Non-heating';
utilityCategory = `Non-heating`;
} else if (client.phone) {
utilityCategory = 'Telephone';
utilityCategory = `Telephone`;
} else {
utilityCategory = 'Zero Utility Expenses';
utilityCategory = `Zero Utility Expenses`;
}

return SNAPData.UTILITY_COST_BRACKETS[ utilityCategory ];
Expand Down Expand Up @@ -396,7 +393,7 @@ hlp.getGrossIncomeLimit = function (client) {
// Data is given in yearly amounts
limit = getLimitBySize(data, numPeople, 200),
// Needs to be gov money rounded?
monthly = toMonthlyFrom(limit, 'yearly');
monthly = toMonthlyFrom(limit, `yearly`);
return monthly;
};

Expand Down Expand Up @@ -450,8 +447,11 @@ hlp.isElderlyOrDisabled = function (member) {
*/
hlp.isHomeless = function(client) {
// Worth abstracting - used a few places and may change
return client.housing === 'homeless';
return client.housing === `homeless`;
};


export { getSNAPBenefits, SNAPhelpers };
export {
getSNAPBenefits,
SNAPhelpers,
};
103 changes: 53 additions & 50 deletions src/programs/massachusetts/section8.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ const getSection8Benefit = function (client, timeframe) {
/** @todo Just return number values */

// Current subsidy MUST already be known in every case
if (timeframe === 'current') {
if (timeframe === `current`) {
return client.current.contractRent - client.current.rentShare;
}

let ttps = hlp.getTTPs(client),
diff = ttps.newTTP - ttps.oldTTP,
newShare = diff + client.current.rentShare,
contrRent = client.current.contractRent;
let ttps = hlp.getTTPs(client),
diff = ttps.newTTP - ttps.oldTTP,
newShare = diff + client.current.rentShare,
contrRent = client.current.contractRent;

// Don't pay more rent than the landlord is asking for
let maxShare = Math.min(contrRent, newShare),
newSubsidy = contrRent - maxShare;
let maxShare = Math.min(contrRent, newShare),
newSubsidy = contrRent - maxShare;

return newSubsidy;
}; // End getSection8Benefit
};


const section8Helpers = {},
Expand All @@ -72,11 +72,11 @@ const section8Helpers = {},
* {@link http://www.tacinc.org/media/58886/S8MS%20Full%20Book.pdf}
*/
hlp.getTTPs = function (client) {
let oldNet = hlp.getNetIncome(client, 'current'),
newNet = hlp.getNetIncome(client, 'future');
let oldNet = hlp.getNetIncome(client, `current`),
newNet = hlp.getNetIncome(client, `future`);

let oldAdj = hlp.getAdjustedIncome(client, 'current', oldNet),
newAdj = hlp.getAdjustedIncome(client, 'future', newNet);
let oldAdj = hlp.getAdjustedIncome(client, `current`, oldNet),
newAdj = hlp.getAdjustedIncome(client, `future`, newNet);

/** @todo A placeholder till we know what to do with negative values */
oldAdj = Math.max(0, oldAdj);
Expand All @@ -94,7 +94,7 @@ hlp.getTTPs = function (client) {
ttps = { oldTTP: oldMaxTTP, newTTP: newMaxTTP };

return ttps;
}; // End hlp.getTTPs()
};


// =============================
Expand All @@ -106,7 +106,7 @@ hlp.getNetIncome = function (client, timeframe) {
gross = unearned + client[ timeframe ].earned;
// net = gross - incomeExclusions, but income exclusions not accounted for for MVP
return gross;
}; // End hlp.getNetIncome()
};


// =============================
Expand All @@ -125,28 +125,30 @@ hlp.getAdjustedIncome = function (client, timeframe, net) {
let time = timeframe, // shorter
allowances = [];

// @todo Move hard-coded numbers to data file
// #4 & #5
let depAllowanceAnnual = getDependentsOfHousehold(client[ time ]).length * 480;
allowances.push(depAllowanceAnnual / 12);
// #6
let childcare = sumProps(client[ time ], UNDER13_CARE_EXPENSES),
ccIncome = client[ time ].earnedBecauseOfChildCare,
/* @todo If student or looking for work, during those hours the expense isn't limited? 2007 Ch. 5 doc */
ccMin = Math.min(childcare, ccIncome);
allowances.push(ccMin);
let childcare = sumProps(client[ time ], UNDER13_CARE_EXPENSES),
childcareIncome = client[ time ].earnedBecauseOfChildCare,
// @todo If student or looking for work, during those hours the expense isn't limited? 2007 Ch. 5 doc
childcareMinimumAllowance = Math.min(childcare, childcareIncome);
allowances.push(childcareMinimumAllowance);
// #7 - 13
let disAndMed = hlp.getDisabledAndMedicalAllowancesSum(client, time, net);
allowances.push(disAndMed);
let disabledAndMedicalAllowances = hlp.getDisabledAndMedicalAllowancesSum(client, time, net);
allowances.push(disabledAndMedicalAllowances);
// #14 (yes, they mean head or spouse here)
if (hlp.hasDsbOrEldHeadOrSpouse(client, time)) {
// @todo Put number in hard-coded data tables
if (hlp.hasDisabledOrElderlyHeadOrSpouse(client, time)) {
allowances.push(400 / 12);
}

let total = sum(allowances),
adj = net - total;
let total = sum(allowances),
adjusted = net - total;

return Math.max(0, adj);
}; // End hlp.getAdjustedIncome()
return Math.max(0, adjusted);
};


/** Returns medical allowance needs assistance allowance amounts.
Expand All @@ -160,78 +162,79 @@ hlp.getAdjustedIncome = function (client, timeframe, net) {
hlp.getDisabledAndMedicalAllowancesSum = function (client, timeframe, net) {

let time = timeframe, // shorter
// @todo Put number in hard-coded data tables
netSubtractor = net * 0.03; // #8, #13

// ----- Assistance Allowance #C, #7 - 11 ----- \\
if (!hlp.hasAnyDsbOrElderly(client, time)) {
if (!hlp.hasAnyDisabledOrElderly(client, time)) {
return 0;
}
// pg 5-30 to 5-31
let handcpExpense = client[ time ].disabledAssistance, // #7
assistanceRemainder = handcpExpense - netSubtractor, // #9
let handicapExpense = client[ time ].disabledAssistance, // #7
assistanceRemainder = handicapExpense - netSubtractor, // #9
handicapAllowance = hlp.getMinHandicapAllowance(client, time, assistanceRemainder); // #10, #11

// ----- Maybe Stop, #D ----- \\
// Only keep going if there's a disabled/elderly head or spouse (or sole member)
if (!hlp.hasDsbOrEldHeadOrSpouse(client, time)) {
if (!hlp.hasDisabledOrElderlyHeadOrSpouse(client, time)) {
return handicapAllowance;
}

// ----- Medical Allowance #12 - 13 ----- \\
let medicalExpenses = hlp.getMedicalExpenses(client, time);
// Read all of pg 5-32 and 5-34 for the following conditional.
// Jumps around because cases are overlapping.
let medAllowance = 0;
let medicalAllowance = 0;
// #13a, pg 5-32 bottom (5-33 to 5-34 example falls in here)
// Note: #13 forgets the '>=' part and just says '>'
if (assistanceRemainder >= 0) {
medAllowance = medicalExpenses;
medicalAllowance = medicalExpenses;
}
// #13b; pg 5-33 middle /and/ pg 5-32 middle, above "special calcuations"
// In both cases handcpExpense is >= 0 and can be safely added.
// In both cases handicapExpense is >= 0 and can be safely added.
else {
let sum = medicalExpenses + handcpExpense;
medAllowance = sum - netSubtractor;
let sum = medicalExpenses + handicapExpense;
medicalAllowance = sum - netSubtractor;
}

let medMin = Math.max(0, medAllowance);
return handicapAllowance + medMin; // #15 contribution ( #11 + #13 )
}; // End hlp.getDisabledAndMedicalAllowancesSum()
let minimumMedicalAllowance = Math.max(0, medicalAllowance);
return handicapAllowance + minimumMedicalAllowance; // #15 contribution ( #11 + #13 )
}; // Ends hlp.getDisabledAndMedicalAllowancesSum()


hlp.getMinHandicapAllowance = function (client, time, assistanceRemainder) {
let asstIncome = client[ time ].earnedBecauseOfAdultCare, // #10
hcapAllowance = Math.min(assistanceRemainder, asstIncome), // #11
hcapMin = Math.max(0, hcapAllowance); // Don't get negative
return hcapMin;
let asstancetIncome = client[ time ].earnedBecauseOfAdultCare, // #10
handicapAllowance = Math.min(assistanceRemainder, asstancetIncome), // #11
handicapAllowanceMinimum = Math.max(0, handicapAllowance); // Don't get negative
return handicapAllowanceMinimum;
};


hlp.getMedicalExpenses = function (client, time) {
// ----- Medical Allowance #12 - 13 ----- \\
// #12, pg 5-31 to 5-32
let disOrElderlyMedical = client[ time ].disabledMedical,
let disabledOrElderlyMedicalExpenses = client[ time ].disabledMedical,
// pg 5-31 says all medical expenses count for this household
otherMedical = client[ time ].otherMedical,
medicalExpenses = disOrElderlyMedical + otherMedical; // #12
medicalExpenses = disabledOrElderlyMedicalExpenses + otherMedical; // #12

return medicalExpenses;
};


// @todo Put number in hard-coded data tables
hlp.isDisabledOrElderly = function (member) {
return member.m_age >= 62 || isDisabled(member);
}; // End hlp.isDisabledOrElderly()
};


// Sure, we could combine these last two, but may be easier to test this way
hlp.hasAnyDsbOrElderly = function (client, timeframe) {
hlp.hasAnyDisabledOrElderly = function (client, timeframe) {
let numMatches = getEveryMemberOfHousehold(client[ timeframe ], hlp.isDisabledOrElderly).length;
return numMatches > 0;
}; // End hlp.hasAnyDsbOrElderly()
};


hlp.hasDsbOrEldHeadOrSpouse = function (client, timeframe) {
hlp.hasDisabledOrElderlyHeadOrSpouse = function (client, timeframe) {

let comboTest = function (member) {
return hlp.isDisabledOrElderly(member) && isHeadOrSpouse(member);
Expand All @@ -240,7 +243,7 @@ hlp.hasDsbOrEldHeadOrSpouse = function (client, timeframe) {

return numMatches > 0;

}; // End hlp.hasDsbOrEldHeadOrSpouse()
};


export {
Expand Down
16 changes: 8 additions & 8 deletions src/test/programs/massachusetts/housing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ describe('section8Helpers', () => {
expect(section8Helpers.isDisabledOrElderly(current.household[ 0 ])).toEqual(true);
});

// `section8Helpers.hasAnyDsbOrElderly()`
// `section8Helpers.hasAnyDisabledOrElderly()`

describe('`.hasAnyDsbOrElderly` given a disabled and elderly member', () => {
it('should be greater than zero', () => {
expect(section8Helpers.hasAnyDsbOrElderly(defaultClient, 'current')).toEqual(true);
describe('`.hasAnyDisabledOrElderly` given a disabled and elderly member', () => {
it('should return true', () => {
expect(section8Helpers.hasAnyDisabledOrElderly(defaultClient, 'current')).toEqual(true);
});
});

// `section8Helpers.hasDsbOrEldHeadOrSpouse()`
// `section8Helpers.hasDisabledOrElderlyHeadOrSpouse()`

describe('`.hasDsbOrEldHeadOrSpouse` given a disabled and elderly head', () => {
it('should be greater than zero', () => {
expect(section8Helpers.hasDsbOrEldHeadOrSpouse(defaultClient, 'current')).toEqual(true);
describe('`.hasDisabledOrElderlyHeadOrSpouse` given a disabled and elderly head', () => {
it('should return true', () => {
expect(section8Helpers.hasDisabledOrElderlyHeadOrSpouse(defaultClient, 'current')).toEqual(true);
});
});

Expand Down

0 comments on commit 70bd223

Please sign in to comment.