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

New CSV validation rules #88

Merged
merged 1 commit into from
Dec 6, 2023
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
37 changes: 34 additions & 3 deletions backend/src/v1/services/validate-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,41 @@ describe("validateRow", () => {

//expect one line error that mentions both COL_HOURS_WORKED and COL_SPECIAL_SALARY
expect(lineErrors).not.toBeNull();
expect(lineErrors?.errors?.length).toBe(1);
expect(doesAnyLineErrorContain(lineErrors, COL_HOURS_WORKED)).toBeTruthy();
expect(doesAnyLineErrorContain(lineErrors, COL_SPECIAL_SALARY)).toBeTruthy();
expect(doesAnyLineErrorContainAll(lineErrors, [COL_HOURS_WORKED, COL_SPECIAL_SALARY])).toBeTruthy();
})
})

describe(`given an row that specifies ${COL_HOURS_WORKED} but not ${COL_ORDINARY_PAY}`, () => {
it("returns a line error", () => {

const overrides = {};
overrides[COL_HOURS_WORKED] = 20;
overrides[COL_ORDINARY_PAY] = NO_DATA_VALUES[0];
overrides[COL_SPECIAL_SALARY] = NO_DATA_VALUES[0];
const invalidRow: Row = createSampleRow(overrides);

const lineNum = 1;
const lineErrors: LineErrors = validateService.validateRow(lineNum, invalidRow);

//expect one line error that mentions both COL_HOURS_WORKED and COL_ORDINARY_PAY
expect(doesAnyLineErrorContainAll(lineErrors, [COL_HOURS_WORKED, COL_ORDINARY_PAY])).toBeTruthy();
})
})

describe(`given an row that specifies ${COL_ORDINARY_PAY} but not ${COL_HOURS_WORKED}`, () => {
it("returns a line error", () => {

const overrides = {};
overrides[COL_HOURS_WORKED] = NO_DATA_VALUES[0];
overrides[COL_ORDINARY_PAY] = 35;
overrides[COL_SPECIAL_SALARY] = NO_DATA_VALUES[0];
const invalidRow: Row = createSampleRow(overrides);

const lineNum = 1;
const lineErrors: LineErrors = validateService.validateRow(lineNum, invalidRow);

//expect one line error that mentions both COL_HOURS_WORKED and COL_ORDINARY_PAY
expect(doesAnyLineErrorContainAll(lineErrors, [COL_HOURS_WORKED, COL_ORDINARY_PAY])).toBeTruthy();
})
})

Expand Down
8 changes: 8 additions & 0 deletions backend/src/v1/services/validate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ const validateService = {
this.isZeroSynonym(record[COL_SPECIAL_SALARY])) {
errorMessages.push(`${COL_SPECIAL_SALARY} must contain data when ${COL_HOURS_WORKED} and ${COL_ORDINARY_PAY} do not contain data.`)
}
if (this.isZeroSynonym(record[COL_HOURS_WORKED]) &&
!this.isZeroSynonym(record[COL_ORDINARY_PAY])) {
errorMessages.push(`${COL_HOURS_WORKED} must not be blank or 0 when ${COL_ORDINARY_PAY} contains data.`)
}
if (this.isZeroSynonym(record[COL_ORDINARY_PAY]) &&
!this.isZeroSynonym(record[COL_HOURS_WORKED])) {
errorMessages.push(`${COL_ORDINARY_PAY} must not be blank or 0 when ${COL_HOURS_WORKED} contains data.`)
}

if (errorMessages.length) {
const lineErrors = {
Expand Down