mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: update plugin data via webhook
This commit is contained in:
parent
e13f9708fd
commit
b8a0aa47bf
3 changed files with 135 additions and 29 deletions
69
tests/Feature/PluginWebhookTest.php
Normal file
69
tests/Feature/PluginWebhookTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plugin;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
test('webhook updates plugin data for webhook strategy', function () {
|
||||
// Create a plugin with webhook strategy
|
||||
$plugin = Plugin::factory()->create([
|
||||
'data_strategy' => 'webhook',
|
||||
'data_payload' => ['old' => 'data'],
|
||||
]);
|
||||
|
||||
// Make request to update plugin data
|
||||
$response = $this->postJson("/api/custom_plugins/{$plugin->uuid}", [
|
||||
'merge_variables' => ['new' => 'data'],
|
||||
]);
|
||||
|
||||
// Assert response
|
||||
$response->assertOk()
|
||||
->assertJson(['message' => 'Data updated successfully']);
|
||||
|
||||
// Assert plugin was updated
|
||||
$this->assertDatabaseHas('plugins', [
|
||||
'id' => $plugin->id,
|
||||
'data_payload' => json_encode(['new' => 'data']),
|
||||
]);
|
||||
});
|
||||
|
||||
test('webhook returns 400 for non-webhook strategy plugins', function () {
|
||||
// Create a plugin with non-webhook strategy
|
||||
$plugin = Plugin::factory()->create([
|
||||
'data_strategy' => 'polling',
|
||||
'data_payload' => ['old' => 'data'],
|
||||
]);
|
||||
|
||||
// Make request to update plugin data
|
||||
$response = $this->postJson("/api/custom_plugins/{$plugin->uuid}", [
|
||||
'merge_variables' => ['new' => 'data'],
|
||||
]);
|
||||
|
||||
// Assert response
|
||||
$response->assertStatus(400)
|
||||
->assertJson(['error' => 'Plugin does not use webhook strategy']);
|
||||
});
|
||||
|
||||
test('webhook returns 400 when merge_variables is missing', function () {
|
||||
// Create a plugin with webhook strategy
|
||||
$plugin = Plugin::factory()->create([
|
||||
'data_strategy' => 'webhook',
|
||||
'data_payload' => ['old' => 'data'],
|
||||
]);
|
||||
|
||||
// Make request without merge_variables
|
||||
$response = $this->postJson("/api/custom_plugins/{$plugin->uuid}", []);
|
||||
|
||||
// Assert response
|
||||
$response->assertStatus(400)
|
||||
->assertJson(['error' => 'Request must contain merge_variables key']);
|
||||
});
|
||||
|
||||
test('webhook returns 404 for non-existent plugin', function () {
|
||||
// Make request with non-existent plugin UUID
|
||||
$response = $this->postJson('/api/custom_plugins/'.Str::uuid(), [
|
||||
'merge_variables' => ['new' => 'data'],
|
||||
]);
|
||||
|
||||
// Assert response
|
||||
$response->assertNotFound();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue