mirror of https://github.com/pixelfed/pixelfed
Fix tests
parent
289251985a
commit
888fa1bc30
@ -1,74 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Factories\ProfileFactory;
|
||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComposeControllerTest extends TestCase
|
||||
{
|
||||
use LazilyRefreshDatabase;
|
||||
uses(LazilyRefreshDatabase::class);
|
||||
|
||||
#[Test]
|
||||
public function search_location_can_filter_by_country()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
it('can filter location search results by country', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$profile = ProfileFactory::new()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
$profile = ProfileFactory::new()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$user->update([
|
||||
'profile_id' => $profile->id,
|
||||
]);
|
||||
$user->update([
|
||||
'profile_id' => $profile->id,
|
||||
]);
|
||||
|
||||
$user->refresh();
|
||||
$user->refresh();
|
||||
|
||||
DB::table('places')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'slug' => 'san-francisco-usa',
|
||||
'name' => 'San Francisco',
|
||||
'state' => 'California',
|
||||
'country' => 'USA',
|
||||
'aliases' => null,
|
||||
'lat' => 37.7749,
|
||||
'long' => -122.4194,
|
||||
'score' => 100,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'slug' => 'san-francisco-philippines',
|
||||
'name' => 'San Francisco',
|
||||
'state' => 'Cebu',
|
||||
'country' => 'Philippines',
|
||||
'aliases' => null,
|
||||
'lat' => 10.3,
|
||||
'long' => 123.9,
|
||||
'score' => 50,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
DB::table('places')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'slug' => 'san-francisco-usa',
|
||||
'name' => 'San Francisco',
|
||||
'state' => 'California',
|
||||
'country' => 'USA',
|
||||
'aliases' => null,
|
||||
'lat' => 37.7749,
|
||||
'long' => -122.4194,
|
||||
'score' => 100,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'slug' => 'san-francisco-philippines',
|
||||
'name' => 'San Francisco',
|
||||
'state' => 'Cebu',
|
||||
'country' => 'Philippines',
|
||||
'aliases' => null,
|
||||
'lat' => 10.3,
|
||||
'long' => 123.9,
|
||||
'score' => 50,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->get('/api/v1.1/compose/search/location?q=San%20Francisco%2C%20USA');
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->get('/api/v1.1/compose/search/location?q=San%20Francisco%2C%20USA');
|
||||
|
||||
$response->assertJsonCount(1);
|
||||
$response->assertJsonCount(1);
|
||||
|
||||
$response->assertJsonFragment([
|
||||
'name' => 'San Francisco',
|
||||
'country' => 'USA',
|
||||
]);
|
||||
$response->assertJsonFragment([
|
||||
'name' => 'San Francisco',
|
||||
'country' => 'USA',
|
||||
]);
|
||||
|
||||
$response->assertJsonMissing([
|
||||
'country' => 'Philippines',
|
||||
]);
|
||||
}
|
||||
}
|
||||
$response->assertJsonMissing([
|
||||
'country' => 'Philippines',
|
||||
]);
|
||||
});
|
||||
|
||||
@ -1,17 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
it('shows the login page', function () {
|
||||
$response = $this->get('login');
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function view_login_page()
|
||||
{
|
||||
$response = $this->get('login');
|
||||
|
||||
$response->assertSee('Forgot Password');
|
||||
}
|
||||
}
|
||||
$response->assertSee('Forgot Password');
|
||||
});
|
||||
|
||||
@ -1,99 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\RemoteAuthInstance;
|
||||
use App\Services\Account\RemoteAuthService;
|
||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RemoteAuthServiceTest extends TestCase
|
||||
{
|
||||
use LazilyRefreshDatabase;
|
||||
uses(LazilyRefreshDatabase::class);
|
||||
|
||||
private function activeInstance(string $domain = 'mastodon.example'): RemoteAuthInstance
|
||||
{
|
||||
return RemoteAuthInstance::create([
|
||||
'domain' => $domain,
|
||||
'client_id' => 'cid',
|
||||
'client_secret' => 'secret',
|
||||
'redirect_uri' => url('/auth/mastodon/callback'),
|
||||
'active' => true,
|
||||
'banned' => false,
|
||||
]);
|
||||
}
|
||||
function activeRemoteAuthInstance(string $domain = 'mastodon.example'): RemoteAuthInstance
|
||||
{
|
||||
return RemoteAuthInstance::create([
|
||||
'domain' => $domain,
|
||||
'client_id' => 'cid',
|
||||
'client_secret' => 'secret',
|
||||
'redirect_uri' => url('/auth/mastodon/callback'),
|
||||
'active' => true,
|
||||
'banned' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function verify_credentials_returns_false_on_connection_failure()
|
||||
{
|
||||
$this->activeInstance();
|
||||
it('returns false on connection failure when verifying credentials', function () {
|
||||
activeRemoteAuthInstance();
|
||||
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
expect($res)->toBeFalse();
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function verify_credentials_returns_false_on_server_error()
|
||||
{
|
||||
$this->activeInstance();
|
||||
it('returns false on server error when verifying credentials', function () {
|
||||
activeRemoteAuthInstance();
|
||||
|
||||
Http::fake([
|
||||
'*' => Http::response('nope', 500),
|
||||
]);
|
||||
Http::fake([
|
||||
'*' => Http::response('nope', 500),
|
||||
]);
|
||||
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
expect($res)->toBeFalse();
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function verify_credentials_returns_json_on_success()
|
||||
{
|
||||
$this->activeInstance();
|
||||
it('returns json on success when verifying credentials', function () {
|
||||
activeRemoteAuthInstance();
|
||||
|
||||
Http::fake([
|
||||
'*' => Http::response(['acct' => 'alice', 'id' => '1'], 200),
|
||||
]);
|
||||
Http::fake([
|
||||
'*' => Http::response(['acct' => 'alice', 'id' => '1'], 200),
|
||||
]);
|
||||
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
$res = RemoteAuthService::getVerifyCredentials('mastodon.example', 'token');
|
||||
|
||||
$this->assertIsArray($res);
|
||||
$this->assertSame('alice', $res['acct']);
|
||||
}
|
||||
expect($res)->toBeArray();
|
||||
expect($res['acct'])->toBe('alice');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function get_following_returns_false_on_connection_failure()
|
||||
{
|
||||
$this->activeInstance();
|
||||
it('returns false on connection failure when getting following', function () {
|
||||
activeRemoteAuthInstance();
|
||||
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
|
||||
$res = RemoteAuthService::getFollowing('mastodon.example', 'token', 42);
|
||||
$res = RemoteAuthService::getFollowing('mastodon.example', 'token', 42);
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
expect($res)->toBeFalse();
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function get_token_returns_false_on_connection_failure()
|
||||
{
|
||||
$this->activeInstance();
|
||||
it('returns false on connection failure when getting a token', function () {
|
||||
activeRemoteAuthInstance();
|
||||
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
Http::fake(function () {
|
||||
throw new ConnectionException('timed out');
|
||||
});
|
||||
|
||||
$res = RemoteAuthService::getToken('mastodon.example', 'code');
|
||||
$res = RemoteAuthService::getToken('mastodon.example', 'code');
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
}
|
||||
expect($res)->toBeFalse();
|
||||
});
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
<?php
|
||||
|
||||
test('that true is true', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function that_true_is_true()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue