Skip to content

Commit

Permalink
feat: update logic to reflect July 2024 IAA and Beneficiary changes (#…
Browse files Browse the repository at this point in the history
…3503)

* feat: update logic to reflect July 2024 IAA and Beneficiary changes

* fix: ensure that the new logic only applies to beneficiaries created after 7/1/2024
  • Loading branch information
as1729 authored Sep 13, 2024
1 parent e6befba commit 9a69163
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,165 @@ describe('findRecipientInDatabase', () => {
});
});

describe('validateIdentifier for IAA', () => {
const validateIdentifier = validateUploadModule.__get__('validateIdentifier');
describe('when subrecipient exists in the database', () => {
it('should return an error if IAA has no UEI or TIN', () => {
const recipient = {
Entity_Type_2__c: 'IAA',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = true;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'IAA subrecipients without UEI or TIN are valid but temporarily not supported by USDR',
{ col: 'C, D', severity: 'err' },
),
]);
});
});
describe('when subrecipient does not exist in the database', () => {
it('should return an error if IAA has no UEI or TIN', () => {
const recipient = {
Entity_Type_2__c: 'IAA',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = false;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'IAA subrecipients without UEI or TIN are valid but temporarily not supported by USDR',
{ col: 'C, D', severity: 'err' },
),
]);
});
});
});

describe('validateIdentifier for Beneficiary', () => {
const validateIdentifier = validateUploadModule.__get__('validateIdentifier');
describe('when subrecipient exists in the database', () => {
describe('subrecipients created prior to July 1st 2024', () => {
it('should return an error if recipient is an existing Beneficiary and only has a UEI', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: '0123456789ABCDEF',
EIN__c: null,
};
const recipientExists = { created_at: new Date('2024-06-30T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should not return an error if recipient is not a new beneficiary and has a TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: '123456789',
};
const recipientExists = { created_at: new Date('2024-06-30T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should return an error if recipient is not a new beneficiary and has neither UEI nor TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = { created_at: new Date('2024-06-30T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'At least one of UEI or TIN/EIN must be set, but both are missing',
{ col: 'C, D', severity: 'err' },
),
]);
});
});
describe('subrecipients created on or after July 1st 2024', () => {
it('should return an error if recipient is an existing Beneficiary and only has a UEI', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: '0123456789ABCDEF',
EIN__c: null,
};
const recipientExists = { created_at: new Date('2024-07-02T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
),
]);
});

it('should not return an error if recipient is not a new beneficiary and has a TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: '123456789',
};
const recipientExists = { created_at: new Date('2024-07-01T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should return an error if recipient is not a new beneficiary and has neither UEI nor TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = { created_at: new Date('2024-07-02T00:00:00') };
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
),
]);
});
});
});
describe('when subrecipient does not exist in the database', () => {
it('should return an error if recipient is a new beneficiary and has no UEI or TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = false;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
),
]);
});
it('should return an error if recipient is a new Beneficiary and only has a UEI', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: '0123456789ABCDEF',
EIN__c: null,
};
const recipientExists = false;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
),
]);
});
});
});

describe('validateIdentifier', () => {
const validateIdentifier = validateUploadModule.__get__('validateIdentifier');
it('should return an error if recipient is a new subrecipient and has no UEI', () => {
Expand Down Expand Up @@ -249,22 +408,6 @@ describe('validateIdentifier', () => {
]);
});

it('should return an error if recipient is a new beneficiary and has no UEI or TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = false;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'At least one of UEI or TIN/EIN must be set, but both are missing',
{ col: 'C, D', severity: 'err' },
),
]);
});

it('should return an error if entity type is semicolon-separated list that includes Subrecipient, and it has an UEI', () => {
const recipient = {
Entity_Type_2__c: 'Subrecipient;Benificiary',
Expand All @@ -281,7 +424,7 @@ describe('validateIdentifier', () => {
]);
});

it('should not return an error if recipient is a new subrecipient or contractor and has a UEI', () => {
it('should not return an error if recipient is a new subrecipient and has a UEI', () => {
const recipient = {
Entity_Type_2__c: 'Subrecipient',
Unique_Entity_Identifier__c: '0123456789ABCDEF',
Expand Down Expand Up @@ -324,44 +467,6 @@ describe('validateIdentifier', () => {
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should not return an error if recipient is not a new subrecipient or contractor and has a UEI', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: '0123456789ABCDEF',
EIN__c: null,
};
const recipientExists = true;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should not return an error if recipient is not a new subrecipient or contractor and has a TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: '123456789',
};
const recipientExists = true;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, []);
});

it('should return an error if recipient is not a new subrecipient or contractor and has neither UEI nor TIN', () => {
const recipient = {
Entity_Type_2__c: 'Beneficiary',
Unique_Entity_Identifier__c: null,
EIN__c: null,
};
const recipientExists = true;
const errors = validateIdentifier(recipient, recipientExists);
assert.deepStrictEqual(errors, [
new ValidationError(
'At least one of UEI or TIN/EIN must be set, but both are missing',
{ col: 'C, D', severity: 'err' },
),
]);
});
});

describe('recipientBelongsToUpload', () => {
Expand Down
31 changes: 29 additions & 2 deletions packages/server/src/arpa_reporter/services/validate-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,46 @@ function validateIdentifier(recipient, recipientExists) {
const hasUEI = Boolean(recipient.Unique_Entity_Identifier__c);
const hasTIN = Boolean(recipient.EIN__c);
const entityType = recipient.Entity_Type_2__c;
const isContractorOrBeneficiary = (entityType.includes('Contractor') || entityType.includes('Beneficiary'));
const isContractor = entityType.includes('Contractor');
const isBeneficiary = entityType.includes('Beneficiary');
const isSubrecipient = entityType.includes('Subrecipient');
const isIAA = entityType.includes('IAA');

if (isSubrecipient && !recipientExists && !hasUEI) {
errors.push(new ValidationError(
'UEI is required for all new subrecipients',
{ col: 'C', severity: 'err' },
));
} else if (isContractorOrBeneficiary && !hasUEI && !hasTIN) {
} else if (isContractor && !hasUEI && !hasTIN) {
errors.push(new ValidationError(
'At least one of UEI or TIN/EIN must be set, but both are missing',
{ col: 'C, D', severity: 'err' },
));
} else if (isBeneficiary && recipientExists) {
if (recipientExists.created_at < new Date('2024-07-01') && !hasTIN && !hasUEI) {
// For existing beneficiaries created before July 1st 2024 ensure that a UEI or TIN is provided.
errors.push(new ValidationError(
'At least one of UEI or TIN/EIN must be set, but both are missing',
{ col: 'C, D', severity: 'err' },
));
} else if (recipientExists.created_at >= new Date('2024-07-01') && !hasTIN) {
// For existing beneficiaries created after July 1st 2024 ensure that a TIN is provided
errors.push(new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
));
}
} else if (isBeneficiary && !recipientExists && !hasTIN) {
// All new beneficiaries must have a TIN.
errors.push(new ValidationError(
'You must enter a TIN for this subrecipient',
{ col: 'D', severity: 'err' },
));
} else if (isIAA && !hasUEI && !hasTIN) {
errors.push(new ValidationError(
'IAA subrecipients without UEI or TIN are valid but temporarily not supported by USDR',
{ col: 'C, D', severity: 'err' },
));
}

return errors;
Expand Down

0 comments on commit 9a69163

Please sign in to comment.