-
Notifications
You must be signed in to change notification settings - Fork 3
Add case insensitivity to email search + test cases #1042
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -121,4 +121,8 @@ public function sendEmailVerificationNotification() { | |
| public function getEmailForVerification() { | ||
| return $this->email; | ||
| } | ||
|
|
||
| public function scopeWhereEmailInsensitive($query, string $email) { | ||
| return $query->whereRaw('LOWER(email) = ?', [strtolower($email)]); | ||
|
Member
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. Is this required? Looking at the quick test I did the case-insensitive searching worked for the Platform API We should still keep the tests that prove that case-insensitive search works, though. P.S. an FYI for the future, |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,10 @@ | |||||||
| use Tests\TestCase; | ||||||||
|
|
||||||||
| class CheckUserEmailExistTest extends TestCase { | ||||||||
| protected function tearDown(): void { | ||||||||
| User::query()->delete(); | ||||||||
|
Member
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.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| public function testItFindsEmailInApiUsersTable() { | ||||||||
| User::factory()->create([ | ||||||||
| 'email' => 'user@example.com', | ||||||||
|
|
@@ -51,4 +55,13 @@ public function testEmailFoundInWikiDb() { | |||||||
| ->expectsOutput('FOUND: test@example.com in mwdb_test.mwdb_test_user') | ||||||||
| ->assertExitCode(0); | ||||||||
| } | ||||||||
|
|
||||||||
| public function testCaseInsensitive() { | ||||||||
| User::factory()->create([ | ||||||||
rosalieper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| 'email' => 'Test@Example.com', | ||||||||
| ]); | ||||||||
| $exists = User::whereEmailInsensitive('tEsT@eXaMpLe.CoM')->exists(); | ||||||||
|
|
||||||||
| $this->assertTrue($exists); | ||||||||
| } | ||||||||
| } | ||||||||
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.
This looks interesting, and it's not immediately obvious to me why it is needed. Can we add a comment above this line to explain it?
Uh oh!
There was an error while loading. Please reload this page.
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.
Looking at the table schema, the datatype of the
user_emailfield istinyblob, so I guess it makes sense (or is maybe even necessary) for the comparison: https://github.com/wbstack/api/blob/main/database/mw/new/mw1.43-wbs2.sql#L1005edit:
gave it a quick test: