Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public function workflowId()

public function webhookUrl(string $signalMethod = ''): string
{
$basePath = config('workflows.webhooks_route', '/webhooks');
$workflow = Str::kebab(class_basename($this->storedWorkflow->class));

if ($signalMethod === '') {
return url("{$basePath}/{$workflow}");
return route("workflows.start.{$workflow}");
}
Comment thread
rmcdaniel marked this conversation as resolved.

$signal = Str::kebab($signalMethod);
return url("{$basePath}/signal/{$workflow}/{$this->storedWorkflow->id}/{$signal}");
return route("workflows.signal.{$workflow}.{$signal}", [
'workflowId' => $this->storedWorkflow->id,
]);
}

public function handle()
Expand Down
4 changes: 2 additions & 2 deletions src/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static function registerWorkflowWebhooks($workflow, $basePath)
return response()->json([
'message' => 'Workflow started',
]);
});
})->name("workflows.start.{$slug}");
}
}
}
Expand All @@ -111,7 +111,7 @@ static function (Request $request, $workflowId) use ($workflow, $method) {
'message' => 'Signal sent',
]);
}
);
)->name("workflows.signal.{$slug}.{$signal}");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Workflow\ActivityStub;
use Workflow\QueryMethod;
use Workflow\SignalMethod;
use Workflow\Webhook;
use Workflow\Workflow;
use Workflow\WorkflowStub;

#[Webhook]
class TestWorkflow extends Workflow
{
public $connection = 'redis';
Expand All @@ -20,6 +22,7 @@ class TestWorkflow extends Workflow
private bool $canceled = false;

#[SignalMethod]
#[Webhook]
public function cancel(): void
{
$this->canceled = true;
Expand Down
7 changes: 5 additions & 2 deletions tests/Unit/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Workflow\Serializers\Serializer;
use Workflow\States\WorkflowCreatedStatus;
use Workflow\States\WorkflowFailedStatus;
use Workflow\Webhooks;
use Workflow\WorkflowStub;

final class ActivityTest extends TestCase
Expand Down Expand Up @@ -125,12 +126,14 @@ public function testActivityAlreadyComplete(): void

public function testWebhookUrl(): void
{
Webhooks::routes('Tests\\Fixtures', __DIR__ . '/../Fixtures');

$workflow = WorkflowStub::load(WorkflowStub::make(TestWorkflow::class)->id());
$activity = new TestOtherActivity(0, now()->toDateTimeString(), StoredWorkflow::findOrFail($workflow->id()), [
'other',
]);

$this->assertSame('http://localhost/webhooks/test-workflow', $activity->webhookUrl());
$this->assertSame('http://localhost/webhooks/signal/test-workflow/1/other', $activity->webhookUrl('other'));
$this->assertSame('http://localhost/webhooks/start/test-workflow', $activity->webhookUrl());
$this->assertSame('http://localhost/webhooks/signal/test-workflow/1/cancel', $activity->webhookUrl('cancel'));
}
}
16 changes: 5 additions & 11 deletions tests/Unit/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,13 @@ public function testResolveNamedParametersUsesDefaults()

public function testWebhookRegistration()
{
$response = $this->postJson('/webhooks/signal/test-webhook-workflow/1/cancel');

Route::shouldReceive('post')
->once()
->withArgs(static function ($uri, $callback) {
return str_contains($uri, 'webhooks/start/test-webhook-workflow');
});
$routeMock = Mockery::mock();
$routeMock->shouldReceive('name')
->andReturnSelf();

Route::shouldReceive('post')
->once()
->withArgs(static function ($uri, $callback) {
return str_contains($uri, 'webhooks/signal/test-webhook-workflow/{workflowId}/cancel');
});
->times(4)
->andReturn($routeMock);

Webhooks::routes('Tests\\Fixtures', __DIR__ . '/../Fixtures');
}
Expand Down