mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-03 05:56:52 +01:00 
			
		
		
		
	* Just skip this table because it no longer exists * Add postgresql * This no longer needs to be there * These are the same output in mysql, but different in postgresql * Fix these migrations for postgresql * This table no longer exists * This is expected to be a json column for json operations, required for postgresql * Shoot for the stars * Fix pint * Why was this missing * Updates * Restore this * This needs to be explicit * Don’t like strings * Fix these classes * Use different method to compare dates * Apparently postgresql doesn’t like case insensitivity * Postgresql orders it backwards * Ordered different by postgresql * Unnecessary and breaking * Make sure the order is correct for postresql * Fix this with the order too * Remove this * Force email to be lowercased * Update app/Models/User.php
		
			
				
	
	
		
			72 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Tests\Integration\Api\Client;
 | 
						|
 | 
						|
use App\Models\Task;
 | 
						|
use App\Models\Backup;
 | 
						|
use App\Models\Server;
 | 
						|
use App\Models\Schedule;
 | 
						|
use Illuminate\Support\Collection;
 | 
						|
use App\Models\Allocation;
 | 
						|
use App\Tests\Integration\IntegrationTestCase;
 | 
						|
use Illuminate\Database\Eloquent\Model;
 | 
						|
use App\Transformers\Api\Client\BaseClientTransformer;
 | 
						|
 | 
						|
abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Override the default createTestResponse from Illuminate so that we can
 | 
						|
     * just dump 500-level errors to the screen in the tests without having
 | 
						|
     * to keep re-assigning variables.
 | 
						|
    protected function createTestResponse($response, $request): \Illuminate\Testing\TestResponse
 | 
						|
    {
 | 
						|
        return TestResponse::fromBaseResponse($response);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns a link to the specific resource using the client API.
 | 
						|
     */
 | 
						|
    protected function link(mixed $model, ?string $append = null): string
 | 
						|
    {
 | 
						|
        switch (get_class($model)) {
 | 
						|
            case Server::class:
 | 
						|
                $link = "/api/client/servers/$model->uuid";
 | 
						|
                break;
 | 
						|
            case Schedule::class:
 | 
						|
                $link = "/api/client/servers/{$model->server->uuid}/schedules/$model->id";
 | 
						|
                break;
 | 
						|
            case Task::class:
 | 
						|
                $link = "/api/client/servers/{$model->schedule->server->uuid}/schedules/{$model->schedule->id}/tasks/$model->id";
 | 
						|
                break;
 | 
						|
            case Allocation::class:
 | 
						|
                $link = "/api/client/servers/{$model->server->uuid}/network/allocations/$model->id";
 | 
						|
                break;
 | 
						|
            case Backup::class:
 | 
						|
                $link = "/api/client/servers/{$model->server->uuid}/backups/$model->uuid";
 | 
						|
                break;
 | 
						|
            default:
 | 
						|
                throw new \InvalidArgumentException(sprintf('Cannot create link for Model of type %s', class_basename($model)));
 | 
						|
        }
 | 
						|
 | 
						|
        return $link . ($append ? '/' . ltrim($append, '/') : '');
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Asserts that the data passed through matches the output of the data from the transformer. This
 | 
						|
     * will remove the "relationships" key when performing the comparison.
 | 
						|
     */
 | 
						|
    protected function assertJsonTransformedWith(array $data, Model $model): void
 | 
						|
    {
 | 
						|
        $reflect = new \ReflectionClass($model);
 | 
						|
        $transformer = sprintf('\\App\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName());
 | 
						|
 | 
						|
        $transformer = new $transformer();
 | 
						|
        $this->assertInstanceOf(BaseClientTransformer::class, $transformer);
 | 
						|
 | 
						|
        $this->assertSame(
 | 
						|
            $transformer->transform($model),
 | 
						|
            Collection::make($data)->except(['relationships'])->toArray()
 | 
						|
        );
 | 
						|
    }
 | 
						|
}
 |