-
Notifications
You must be signed in to change notification settings - Fork 37
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
Order form is dropping second last names unexpectedly #3113
Changes from all commits
e885fec
0266ff2
8f355b0
6e3f63b
2b2a46d
6bc6314
27f2158
bba2b8d
4ca0bc6
d76f381
3b5294e
2276918
1700a00
c4e267a
2455c15
8f338d2
e085d0c
7b6d579
651e2b9
a243e08
2aca001
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 |
---|---|---|
|
@@ -117,6 +117,10 @@ class WCCustomerMapper @Inject constructor() { | |
} | ||
} | ||
|
||
private fun String?.firstNameFromName() = this?.split(" ")?.firstOrNull() ?: "" | ||
private fun String?.lastNameFromName() = this?.split(" ")?.lastOrNull() ?: "" | ||
// Please refer WCCustomerMapperTest file which serves as documentation of how this function behaves. | ||
private fun String?.firstNameFromName(): String = | ||
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. Wouldn't it do the trick in both cases?
You implementation works, but both (maybe) slow and not easy to read 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 wouldn't work as it fails for names that has leading spaces, multiple spaces in between. For example: 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. Considering that we run this code 6 times per 1 customer mapped I'd propose something simple like that:
It won't remove spaces inside of the first and last name, but IMO, its not what we even want and we should leave it up to the users and the way they want to write their names 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. Done: 2aca001 |
||
this?.trim()?.substringBefore(' ')?.trim().orEmpty() | ||
|
||
private fun String?.lastNameFromName(): String = | ||
this?.trim()?.substringAfter(' ', "")?.trim().orEmpty() | ||
} |
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.
np: in all tests, maybe assert both first and last names, because they kinda related and deducted from one string?
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.
I agree, my reasoning for splitting the test cases is mainly to understand why the test fails in future. There must be only one reason for the failure of tests IMHO. If we combine both, we need to see if the test failed because of logical error in the extraction of first name or last name which could be avoided if the test asserts just one thing.
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.
In my opinion, the one reason here - "if correct logic used in splitting the string". The current implementation, which consists of two private extensions, should not affect the test's logic. Currently, the test does not validate whether the splitter is functioning correctly; instead, it only checks that the first word is designated as the first name.