Fixes for webhooks

This commit is contained in:
David Bomba 2023-02-08 22:37:12 +11:00
parent ba8cc3e44d
commit 5f9784dcf8
5 changed files with 35 additions and 29 deletions

View File

@ -39,6 +39,8 @@ class StoreWebhookRequest extends Request
{
$input = $this->all();
if(!isset($input['rest_method']))
$input['rest_method'] = 'post';
// if(isset($input['headers']) && count($input['headers']) == 0)
// $input['headers'] = null;

View File

@ -44,6 +44,9 @@ class UpdateWebhookRequest extends Request
{
$input = $this->all();
if(!isset($input['rest_method']))
$input['rest_method'] = 'post';
// if(isset($input['headers']) && count($input['headers']) == 0)
// $input['headers'] = null;

View File

@ -59,7 +59,7 @@ class ClientObserver
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $client, $client->company)->delay(0);
WebhookHandler::dispatch($event, $client, $client->company, 'client')->delay(0);
}

View File

@ -58,7 +58,7 @@ class InvoiceObserver
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $invoice, $invoice->company)->delay(0);
WebhookHandler::dispatch($event, $invoice, $invoice->company, 'client')->delay(0);
}
/**

View File

@ -49,33 +49,6 @@ class WebhookAPITest extends TestCase
$this->withoutExceptionHandling();
}
// public function testClientWebhooks()
// {
// // client archived = 37
// $data = [
// 'target_url' => 'http://hook.com',
// 'event_id' => 37,
// 'rest_method' => 'post',
// 'format' => 'JSON',
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->post('/api/v1/webhooks', $data);
// $repo = new ClientRepository(new ClientContactRepository());
// $repo->archive($this->client);
// \Illuminate\Support\Facades\Queue::after(function (WebhookHandler $event) {
// $this->assertTrue($event->job->isReleased());
// });
// \Illuminate\Support\Facades\Queue::assertPushed(WebhookHandler::class);
// }
public function testWebhookGetFilter()
{
$response = $this->withHeaders([
@ -98,6 +71,20 @@ class WebhookAPITest extends TestCase
public function testWebhookPostRoute()
{
$data = [
'target_url' => 'http://hook.com',
'event_id' => 1,
'format' => 'JSON',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/webhooks', $data);
$response->assertStatus(200);
$data = [
'target_url' => 'http://hook.com',
'event_id' => 1,
@ -116,6 +103,20 @@ class WebhookAPITest extends TestCase
$this->assertEquals(1, $arr['data']['event_id']);
$data = [
'target_url' => 'http://hook.com',
'event_id' => 2,
'format' => 'JSON',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->put('/api/v1/webhooks/'.$arr['data']['id'], $data);
$response->assertStatus(200);
$data = [
'target_url' => 'http://hook.com',
'event_id' => 2,