|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Commands; |
| 4 | + |
| 5 | +use App\Services\WikiUserEmailChecker; |
| 6 | +use App\User; |
| 7 | +use Mockery; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class CheckUserEmailExistTest extends TestCase { |
| 11 | + public function testItFindsEmailInApiUsersTable() { |
| 12 | + User::factory()->create([ |
| 13 | + 'email' => 'user@example.com', |
| 14 | + ]); |
| 15 | + |
| 16 | + // Act & Assert |
| 17 | + $this->artisan('wbs-user:check-email', ['emails' => ['user@example.com']]) |
| 18 | + ->expectsOutput('FOUND: user@example.com in apidb.users') |
| 19 | + ->assertExitCode(0); |
| 20 | + } |
| 21 | + |
| 22 | + public function testItReturnsNotFoundIfEmailDoesNotExist() { |
| 23 | + $this->artisan('wbs-user:check-email', ['emails' => ['nonexistent@example.com']]) |
| 24 | + ->expectsOutput('NOT FOUND: nonexistent@example.com') |
| 25 | + ->assertExitCode(0); |
| 26 | + } |
| 27 | + |
| 28 | + public function testItChecksMultipleEmails() { |
| 29 | + User::factory()->create(['email' => 'user1@example.com']); |
| 30 | + |
| 31 | + $emails = ['user1@example.com', 'other@example.com']; |
| 32 | + |
| 33 | + $this->artisan('wbs-user:check-email', ['emails' => $emails]) |
| 34 | + ->expectsOutput('FOUND: user1@example.com in apidb.users') |
| 35 | + ->expectsOutput('NOT FOUND: other@example.com') |
| 36 | + ->assertExitCode(0); |
| 37 | + } |
| 38 | + |
| 39 | + public function testEmailFoundInWikiDb() { |
| 40 | + $checker = Mockery::mock(WikiUserEmailChecker::class); |
| 41 | + |
| 42 | + $checker->shouldReceive('findEmail') |
| 43 | + ->with('test@example.com') |
| 44 | + ->andReturn(['mwdb_test.mwdb_test_user']); |
| 45 | + |
| 46 | + $this->app->instance(WikiUserEmailChecker::class, $checker); |
| 47 | + |
| 48 | + $this->artisan('wbs-user:check-email', [ |
| 49 | + 'emails' => ['test@example.com'], |
| 50 | + ]) |
| 51 | + ->expectsOutput('FOUND: test@example.com in mwdb_test.mwdb_test_user') |
| 52 | + ->assertExitCode(0); |
| 53 | + } |
| 54 | +} |
0 commit comments