Skip to content

Commit

Permalink
Prevent error when listing exceptions (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naugrimm authored Nov 15, 2023
1 parent 3eb81db commit 17bc1ab
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
11 changes: 4 additions & 7 deletions app/Http/Resources/StoredWorkflowExceptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

namespace Waterline\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use SplFileObject;
use Waterline\Transformer\WorkflowToChartDataTransformer;
use Workflow\Models\StoredWorkflow;
use Workflow\Models\StoredWorkflowException;
use Workflow\Serializers\Y;

Expand All @@ -18,9 +15,9 @@ class StoredWorkflowExceptionResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request)
public function toArray($request)
{
$code = null;
$code = '';
$exception = $this->exception;

$unserialized = Y::unserialize($exception);
Expand All @@ -32,11 +29,11 @@ public function toArray(Request $request)
$file = new SplFileObject($unserialized['file']);
$file->seek($unserialized['line'] - 4);
for ($line = 0; $line < 7; ++$line) {
$exception->code .= $file->current();
$code .= $file->current();
$file->next();
if ($file->eof()) break;
}
$code = rtrim($exception->code);
$code = rtrim($code);
$exception = serialize($unserialized);
}

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Resources/StoredWorkflowLogResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Waterline\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Waterline\Transformer\WorkflowToChartDataTransformer;
use Workflow\Models\StoredWorkflow;
use Workflow\Models\StoredWorkflowLog;
use Workflow\Serializers\Y;

Expand All @@ -17,7 +14,7 @@ class StoredWorkflowLogResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request)
public function toArray($request)
{
return [
"id" => $this->id,
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Resources/StoredWorkflowResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Waterline\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Waterline\Transformer\WorkflowToChartDataTransformer;
use Workflow\Models\StoredWorkflow;
Expand All @@ -16,7 +15,7 @@ class StoredWorkflowResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request)
public function toArray($request)
{
return [
"id" => $this->id,
Expand Down
83 changes: 83 additions & 0 deletions tests/Feature/DashboardWorkflowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Waterline\Tests\Feature;

use Exception;
use Illuminate\Testing\Fluent\AssertableJson;
use Waterline\Tests\TestCase;
use Workflow\Models\StoredWorkflow;
use Workflow\Serializers\Y;

class DashboardWorkflowTest extends TestCase
{
public function testIndexNone()
{
$storedWorkflow = StoredWorkflow::create([
'class' => 'WorkflowClass',
'arguments' => 'N;',
'output' => 'N;',
'status' => 'created',
]);

$storedLog = $storedWorkflow->logs()->create([
'index' => 0,
'now' => now()->toDateTimeString(),
'class' => 'Activity1Class',
'result' => 'N;',
]);

$storedWorkflow->exceptions()->create([
'class' => 'Activity2Class',
'exception' => Y::serialize(new Exception('ExceptionMessage')),
]);


$response = $this
->get('/waterline/api/flows/'.$storedWorkflow->id);

$response
->assertStatus(200)
->assertJson(
fn (AssertableJson $json) => $json
->where('id', $storedWorkflow->id)
->where('class', 'WorkflowClass')
->where('arguments', 'N;')
->where('output', 'N;')
->where('status', 'created')
->whereType('created_at', 'string')
->whereType('updated_at', 'string')
->has(
'logs',
1,
fn (AssertableJson $log) => $log
->where('id', $storedLog->id)
->where('index', 0)
->whereType('now', 'string')
->where('class', 'Activity1Class')
->where('result', 'N;')
->whereType('created_at', 'string')
)
->has(
'exceptions',
1,
fn (AssertableJson $exception) => $exception
->whereType('code', 'string')
->whereType('exception', 'string')
->where('class', 'Activity2Class')
->whereType('created_at', 'string')
)
->has('chartData', 2)
->where('chartData.0.x', 'WorkflowClass')
->where('chartData.0.type', 'Workflow')
->where('chartData.1.x', 'Activity1Class')
->where('chartData.1.type', 'Activity')
->whereAllType([
'chartData.0.y.0' => 'integer',
'chartData.0.y.1' => 'integer',
'chartData.1.y.0' => 'integer',
'chartData.1.y.1' => 'integer',
])

);
}
}

0 comments on commit 17bc1ab

Please sign in to comment.