|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Dacastro4\LaravelGmail\LaravelGmailClass; |
3 | 4 | use Dacastro4\LaravelGmail\Services\Message\Mail; |
4 | 5 | use Illuminate\Container\Container; |
5 | 6 | use Illuminate\Mail\Markdown; |
| 7 | +use Illuminate\Support\Facades\Storage; |
6 | 8 | use Tests\TestCase; |
7 | 9 |
|
8 | 10 | class LaravelGmailTest extends TestCase |
@@ -39,4 +41,54 @@ public function test_format_email_list_parses_names_and_addresses() |
39 | 41 | $this->assertEquals(['name' => 'Alice', 'email' => 'alice@example.com'], $formatted[0]); |
40 | 42 | $this->assertEquals(['name' => 'Bob', 'email' => 'bob@example.com'], $formatted[1]); |
41 | 43 | } |
| 44 | + |
| 45 | + /** @test */ |
| 46 | + public function test_user_returns_email_from_token_file() |
| 47 | + { |
| 48 | + Storage::fake('local'); |
| 49 | + |
| 50 | + config([ |
| 51 | + 'gmail.client_secret' => 'secret', |
| 52 | + 'gmail.client_id' => 'client', |
| 53 | + 'gmail.redirect_url' => '/', |
| 54 | + 'gmail.credentials_file_name' => 'test-token', |
| 55 | + 'gmail.allow_json_encrypt' => false, |
| 56 | + 'gmail.allow_multiple_credentials' => false, |
| 57 | + ]); |
| 58 | + |
| 59 | + Storage::disk('local')->put( |
| 60 | + 'gmail/tokens/test-token.json', |
| 61 | + json_encode([ |
| 62 | + 'access_token' => 'token', |
| 63 | + 'refresh_token' => 'refresh', |
| 64 | + 'email' => 'foo@example.com', |
| 65 | + 'expires_in' => 3600, |
| 66 | + 'created' => time(), |
| 67 | + ]) |
| 68 | + ); |
| 69 | + |
| 70 | + $client = new LaravelGmailClass($this->app['config']); |
| 71 | + |
| 72 | + $this->assertEquals('foo@example.com', $client->user()); |
| 73 | + } |
| 74 | + |
| 75 | + /** @test */ |
| 76 | + public function test_set_user_id_updates_property() |
| 77 | + { |
| 78 | + Storage::fake('local'); |
| 79 | + |
| 80 | + config([ |
| 81 | + 'gmail.client_secret' => 'secret', |
| 82 | + 'gmail.client_id' => 'client', |
| 83 | + 'gmail.redirect_url' => '/', |
| 84 | + 'gmail.credentials_file_name' => 'test-token', |
| 85 | + 'gmail.allow_json_encrypt' => false, |
| 86 | + 'gmail.allow_multiple_credentials' => false, |
| 87 | + ]); |
| 88 | + |
| 89 | + $client = new LaravelGmailClass($this->app['config']); |
| 90 | + $client->setUserId('user-123'); |
| 91 | + |
| 92 | + $this->assertEquals('user-123', $client->getUserId()); |
| 93 | + } |
42 | 94 | } |
0 commit comments