-
Notifications
You must be signed in to change notification settings - Fork 52
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
Tweak predictProblems logic, add test for it #2117
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,6 +446,40 @@ describe('predictProblem()', () => { | |
]); | ||
}); | ||
|
||
it('returns problem when either the first name or last name value is missing', () => { | ||
const sheet = makeFullSheet({ | ||
columns: [ | ||
{ | ||
field: 'first_name', | ||
kind: ColumnKind.FIELD, | ||
selected: true, | ||
}, | ||
{ | ||
field: 'last_name', | ||
kind: ColumnKind.FIELD, | ||
selected: true, | ||
}, | ||
{ | ||
field: 'email', | ||
kind: ColumnKind.FIELD, | ||
selected: true, | ||
}, | ||
], | ||
rows: [ | ||
{ data: ['Clara', 'Zetkin', '[email protected]'] }, | ||
{ data: ['John', '', '[email protected]'] }, | ||
], | ||
}); | ||
|
||
const problems = predictProblems(sheet, 'SE', []); | ||
expect(problems).toEqual([ | ||
{ | ||
indices: [1], | ||
kind: ImportProblemKind.MISSING_ID_AND_NAME, | ||
}, | ||
]); | ||
}); | ||
|
||
it('returns no problems when date column is configured and all cells have a value', () => { | ||
const sheet = makeFullSheet({ | ||
columns: [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,6 @@ export function predictProblems( | |
(col) => col.kind == ColumnKind.FIELD && col.field == 'last_name' | ||
); | ||
|
||
if (!sheetHasId) { | ||
if (sheetHasFirstName && sheetHasLastName) { | ||
problems.push({ | ||
kind: ImportProblemKind.UNCONFIGURED_ID, | ||
}); | ||
} else { | ||
problems.push({ | ||
kind: ImportProblemKind.UNCONFIGURED_ID_AND_NAME, | ||
}); | ||
} | ||
} | ||
|
||
function accumulateFieldProblem(field: string, row: number) { | ||
const existing = problemByField[field]; | ||
if (existing) { | ||
|
@@ -75,6 +63,7 @@ export function predictProblems( | |
customFields.forEach((field) => { | ||
customFieldsBySlug[field.slug] = field; | ||
}); | ||
let isMissingValue = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not really sure this variable is doing so much 😅 If I remove it from the code, the only difference is that I get both unconfigured ID error and "not all rows have identifiers" error, instead of just the latter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just for removing unconfigured ID error(yellow box). Thought that it is weird to show yellow box with text "I understand and want to proceed anyway" when there is an error. Should I remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to do what you've tried to do @kaulfield23, but I think the best way to do it is to write a test that reproduces the problem you found, and then fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @richardolsson Okay! will do 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that case is already covered with the test I wrote ( test : returns problem when either the first name or last name value is missing ) . And the case that ziggi found is already covered with another test that already exists ( test : returns problem when ID or name are not configured ) Is there a case that I have not added? @richardolsson |
||
|
||
sheet.rows.forEach((row, index) => { | ||
const rowIndex = sheet.firstRowIsHeaders ? index - 1 : index; | ||
|
@@ -133,11 +122,13 @@ export function predictProblems( | |
} | ||
} | ||
hadImpact = true; | ||
} else { | ||
isMissingValue = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made me a bit confused - this will be set to true if any "cell" in the sheet is empty, no matter if it is name/id or not. |
||
} | ||
} | ||
}); | ||
|
||
if (sheetHasId && sheetHasFirstName && sheetHasLastName) { | ||
if (sheetHasFirstName && sheetHasLastName) { | ||
if (!rowHasId && (!rowHasFirstName || !rowHasLastName)) { | ||
if (!rowProblemByKind[ImportProblemKind.MISSING_ID_AND_NAME]) { | ||
rowProblemByKind[ImportProblemKind.MISSING_ID_AND_NAME] = { | ||
|
@@ -153,6 +144,18 @@ export function predictProblems( | |
} | ||
}); | ||
|
||
if (!sheetHasId && !isMissingValue) { | ||
if (sheetHasFirstName && sheetHasLastName) { | ||
problems.push({ | ||
kind: ImportProblemKind.UNCONFIGURED_ID, | ||
}); | ||
} else { | ||
problems.push({ | ||
kind: ImportProblemKind.UNCONFIGURED_ID_AND_NAME, | ||
}); | ||
} | ||
} | ||
|
||
if (!hadImpact) { | ||
problems.push({ | ||
kind: ImportProblemKind.NO_IMPACT, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try creating another test that is a copy of this one, except that this column is not configured (
ColumnKind.UNKNOWN
andselected: false
). In my experimentation, that seems to not return a problem even though it should returnUNCONFIGURED_ID_AND_NAME
because not the full name has been configured.