Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a boolean or an object?

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are using recipientExists as an object, it may make sense to rename it to not seem like a boolean.

// 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
Loading