feat(#91): add multi color and palette support

This commit is contained in:
Benjamin Nussbaum 2025-11-22 16:43:33 +01:00
parent 10a956a2b8
commit 0816ad137e
19 changed files with 1696 additions and 185 deletions

View file

@ -12,6 +12,13 @@ uses(RefreshDatabase::class);
beforeEach(function (): void {
DeviceModel::truncate();
// Mock palettes API to return empty array by default
Http::fake([
'usetrmnl.com/api/palettes' => Http::response([
'data' => [],
], 200),
]);
});
test('fetch device models job can be dispatched', function (): void {
@ -21,6 +28,7 @@ test('fetch device models job can be dispatched', function (): void {
test('fetch device models job handles successful api response', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -42,6 +50,10 @@ test('fetch device models job handles successful api response', function (): voi
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 1]);
@ -67,6 +79,7 @@ test('fetch device models job handles successful api response', function (): voi
test('fetch device models job handles multiple device models', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -103,6 +116,10 @@ test('fetch device models job handles multiple device models', function (): void
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 2]);
@ -116,11 +133,16 @@ test('fetch device models job handles multiple device models', function (): void
test('fetch device models job handles empty data array', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [],
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 0]);
@ -133,11 +155,16 @@ test('fetch device models job handles empty data array', function (): void {
test('fetch device models job handles missing data field', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'message' => 'No data available',
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 0]);
@ -150,11 +177,16 @@ test('fetch device models job handles missing data field', function (): void {
test('fetch device models job handles non-array data', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => 'invalid-data',
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('error')
->once()
->with('Invalid response format from device models API', Mockery::type('array'));
@ -167,11 +199,16 @@ test('fetch device models job handles non-array data', function (): void {
test('fetch device models job handles api failure', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'error' => 'Internal Server Error',
], 500),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('error')
->once()
->with('Failed to fetch device models from API', [
@ -187,11 +224,16 @@ test('fetch device models job handles api failure', function (): void {
test('fetch device models job handles network exception', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => function (): void {
throw new Exception('Network connection failed');
},
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('error')
->once()
->with('Exception occurred while fetching device models', Mockery::type('array'));
@ -204,6 +246,7 @@ test('fetch device models job handles network exception', function (): void {
test('fetch device models job handles device model with missing name', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -214,6 +257,10 @@ test('fetch device models job handles device model with missing name', function
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('warning')
->once()
->with('Device model data missing name field', Mockery::type('array'));
@ -230,6 +277,7 @@ test('fetch device models job handles device model with missing name', function
test('fetch device models job handles device model with partial data', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -240,6 +288,10 @@ test('fetch device models job handles device model with partial data', function
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 1]);
@ -273,6 +325,7 @@ test('fetch device models job updates existing device model', function (): void
]);
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -294,6 +347,10 @@ test('fetch device models job updates existing device model', function (): void
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated device models', ['count' => 1]);
@ -311,6 +368,7 @@ test('fetch device models job updates existing device model', function (): void
test('fetch device models job handles processing exception for individual model', function (): void {
Http::fake([
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
'usetrmnl.com/api/models' => Http::response([
'data' => [
[
@ -327,6 +385,10 @@ test('fetch device models job handles processing exception for individual model'
], 200),
]);
Log::shouldReceive('info')
->once()
->with('Successfully fetched and updated palettes', ['count' => 0]);
Log::shouldReceive('warning')
->once()
->with('Device model data missing name field', Mockery::type('array'));