Skip to content

Commit 7613055

Browse files
committed
Add initial database file and tests for user retrieval
1 parent 5f7d56d commit 7613055

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

database/database.sqlite

Whitespace-only changes.

tests/LaravelGmailTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3+
use Dacastro4\LaravelGmail\LaravelGmailClass;
34
use Dacastro4\LaravelGmail\Services\Message\Mail;
45
use Illuminate\Container\Container;
56
use Illuminate\Mail\Markdown;
7+
use Illuminate\Support\Facades\Storage;
68
use Tests\TestCase;
79

810
class LaravelGmailTest extends TestCase
@@ -39,4 +41,54 @@ public function test_format_email_list_parses_names_and_addresses()
3941
$this->assertEquals(['name' => 'Alice', 'email' => 'alice@example.com'], $formatted[0]);
4042
$this->assertEquals(['name' => 'Bob', 'email' => 'bob@example.com'], $formatted[1]);
4143
}
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+
}
4294
}

0 commit comments

Comments
 (0)