mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
test: use TrmnlPipeline::fake() to speed up test suite
This commit is contained in:
parent
42b515e322
commit
a1a57014b6
9 changed files with 119 additions and 102 deletions
|
|
@ -6,10 +6,15 @@ use App\Enums\ImageFormat;
|
|||
use App\Models\Device;
|
||||
use App\Models\DeviceModel;
|
||||
use App\Services\ImageGenerationService;
|
||||
use Bnussbau\TrmnlPipeline\TrmnlPipeline;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
TrmnlPipeline::fake();
|
||||
});
|
||||
|
||||
it('get_image_settings returns device model settings when available', function (): void {
|
||||
// Create a DeviceModel
|
||||
$deviceModel = DeviceModel::factory()->create([
|
||||
|
|
@ -47,7 +52,7 @@ it('get_image_settings returns device model settings when available', function (
|
|||
expect($settings['offset_x'])->toBe(10);
|
||||
expect($settings['offset_y'])->toBe(20);
|
||||
expect($settings['use_model_settings'])->toBe(true);
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('get_image_settings falls back to device settings when no device model', function (): void {
|
||||
// Create a device without DeviceModel
|
||||
|
|
@ -71,7 +76,7 @@ it('get_image_settings falls back to device settings when no device model', func
|
|||
expect($settings['rotation'])->toBe(180);
|
||||
expect($settings['image_format'])->toBe(ImageFormat::PNG_8BIT_GRAYSCALE->value);
|
||||
expect($settings['use_model_settings'])->toBe(false);
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('get_image_settings uses defaults for missing device properties', function (): void {
|
||||
// Create a device without DeviceModel and missing properties
|
||||
|
|
@ -101,7 +106,7 @@ it('get_image_settings uses defaults for missing device properties', function ()
|
|||
expect($settings['offset_y'])->toBe(0);
|
||||
// image_format defaults to 'auto' when not set
|
||||
expect($settings['image_format'])->toBe('auto');
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('determine_image_format_from_model returns correct formats', function (): void {
|
||||
// Use reflection to access private method
|
||||
|
|
@ -153,7 +158,7 @@ it('determine_image_format_from_model returns correct formats', function (): voi
|
|||
]);
|
||||
$format = $method->invoke(null, $unknownModel);
|
||||
expect($format)->toBe(ImageFormat::AUTO->value);
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('cleanup_folder identifies active images correctly', function (): void {
|
||||
// Create devices with images
|
||||
|
|
@ -189,7 +194,7 @@ it('reset_if_not_cacheable detects device models', function (): void {
|
|||
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBeNull();
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('reset_if_not_cacheable detects custom dimensions', function (): void {
|
||||
// Create a plugin
|
||||
|
|
@ -206,7 +211,7 @@ it('reset_if_not_cacheable detects custom dimensions', function (): void {
|
|||
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBeNull();
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('reset_if_not_cacheable preserves cache for standard devices', function (): void {
|
||||
// Create a plugin
|
||||
|
|
@ -224,7 +229,7 @@ it('reset_if_not_cacheable preserves cache for standard devices', function (): v
|
|||
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBe('test-uuid');
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('reset_if_not_cacheable preserves cache for og_png and og_plus device models', function (): void {
|
||||
// Create a plugin
|
||||
|
|
@ -255,7 +260,7 @@ it('reset_if_not_cacheable preserves cache for og_png and og_plus device models'
|
|||
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBe('test-uuid');
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('reset_if_not_cacheable resets cache for non-standard device models', function (): void {
|
||||
// Create a plugin
|
||||
|
|
@ -277,12 +282,12 @@ it('reset_if_not_cacheable resets cache for non-standard device models', functio
|
|||
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBeNull();
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('reset_if_not_cacheable handles null plugin', function (): void {
|
||||
// Test that the method handles null plugin gracefully
|
||||
expect(fn () => ImageGenerationService::resetIfNotCacheable(null))->not->toThrow(Exception::class);
|
||||
})->skipOnCi();
|
||||
});
|
||||
|
||||
it('image_format enum includes new 2bit 4c format', function (): void {
|
||||
// Test that the new format is properly defined in the enum
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue