From ec5bc577375def8c705395d7ba3ae428f1379a77 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 07:09:47 +1100 Subject: [PATCH 1/8] Minor cleanup --- app/Models/BaseModel.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 988928722164..08ad4823838d 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -206,12 +206,22 @@ class BaseModel extends Model return ctrans('texts.item'); } - public function sendEvent($event_id, $additional_data=""){ + /** + * Model helper to send events for webhooks + * + * @param int $event_id + * @param string $additional_data optional includes + * + * @return void + */ + public function sendEvent(int $event_id, string $additional_data = ""): void + { $subscriptions = Webhook::where('company_id', $this->company_id) - ->where('event_id', $event_id) - ->exists(); + ->where('event_id', $event_id) + ->exists(); + if ($subscriptions) { - WebhookHandler::dispatch($event_id, $this, $this->company, $additional_data)->delay(0); + WebhookHandler::dispatch($event_id, $this, $this->company, $additional_data); } } From c631a05d1cc3836a309e6f17f702634414d53c5c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 07:31:24 +1100 Subject: [PATCH 2/8] Fixes for bank transaction rules --- app/Models/BankTransactionRule.php | 61 ++++++++++--------- .../BankTransactionRuleTransformer.php | 18 ++++-- .../Feature/Bank/BankTransactionRuleTest.php | 4 +- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/app/Models/BankTransactionRule.php b/app/Models/BankTransactionRule.php index 0284e787d703..b7c879d722cd 100644 --- a/app/Models/BankTransactionRule.php +++ b/app/Models/BankTransactionRule.php @@ -18,7 +18,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; class BankTransactionRule extends BaseModel { use SoftDeletes; - use MakesHash; use Filterable; protected $fillable = [ @@ -66,6 +65,37 @@ class BankTransactionRule extends BaseModel private array $search_results = []; + public function getEntityType() + { + return self::class; + } + + public function company() + { + return $this->belongsTo(Company::class); + } + + public function vendor() + { + return $this->belongsTo(Vendor::class); + } + + public function client() + { + return $this->belongsTo(Client::class); + } + + public function user() + { + return $this->belongsTo(User::class)->withTrashed(); + } + + public function expense_category() + { + return $this->belongsTo(ExpenseCategory::class, 'category_id')->withTrashed(); + } + + // rule object looks like this: //[ // { @@ -138,34 +168,5 @@ class BankTransactionRule extends BaseModel // } // } - public function getEntityType() - { - return self::class; - } - - public function company() - { - return $this->belongsTo(Company::class); - } - - public function vendor() - { - return $this->belongsTo(Vendor::class); - } - - public function client() - { - return $this->belongsTo(Client::class); - } - - public function user() - { - return $this->belongsTo(User::class)->withTrashed(); - } - - public function expense_category() - { - return $this->belongsTo(ExpenseCategory::class, 'category_id', 'id')->withTrashed(); - } } \ No newline at end of file diff --git a/app/Transformers/BankTransactionRuleTransformer.php b/app/Transformers/BankTransactionRuleTransformer.php index ffc0aeb4b2e4..ca5628abb32b 100644 --- a/app/Transformers/BankTransactionRuleTransformer.php +++ b/app/Transformers/BankTransactionRuleTransformer.php @@ -13,10 +13,13 @@ namespace App\Transformers; use App\Models\BankTransaction; use App\Models\BankTransactionRule; +use App\Models\Client; use App\Models\Company; use App\Models\ExpenseCategory; -use App\Transformers\VendorTransformer; +use App\Models\Vendor; +use App\Transformers\ExpenseCategoryTransformer; use App\Transformers\ExpenseCateogryTransformer; +use App\Transformers\VendorTransformer; use App\Utils\Traits\MakesHash; /** @@ -74,31 +77,34 @@ class BankTransactionRuleTransformer extends EntityTransformer public function includeClient(BankTransactionRule $bank_transaction_rule) { - $transformer = new ClientTransformer($this->serializer); if(!$bank_transaction_rule->client) return null; - return $this->includeItem($bank_transaction_rule->expense, $transformer, Client::class); + $transformer = new ClientTransformer($this->serializer); + + return $this->includeItem($bank_transaction_rule->client, $transformer, Client::class); } public function includeVendor(BankTransactionRule $bank_transaction_rule) { - $transformer = new VendorTransformer($this->serializer); if(!$bank_transaction_rule->vendor) return null; + $transformer = new VendorTransformer($this->serializer); + return $this->includeItem($bank_transaction_rule->vendor, $transformer, Vendor::class); } public function includeExpenseCategory(BankTransactionRule $bank_transaction_rule) { - $transformer = new ExpenseCategoryTransformer($this->serializer); - if(!$bank_transaction_rule->expense_cateogry) + if(!$bank_transaction_rule->expense_category) return null; + $transformer = new ExpenseCategoryTransformer($this->serializer); + return $this->includeItem($bank_transaction_rule->expense_category, $transformer, ExpenseCategory::class); } diff --git a/tests/Feature/Bank/BankTransactionRuleTest.php b/tests/Feature/Bank/BankTransactionRuleTest.php index 7ee479dd8544..f6a1051d968c 100644 --- a/tests/Feature/Bank/BankTransactionRuleTest.php +++ b/tests/Feature/Bank/BankTransactionRuleTest.php @@ -185,7 +185,7 @@ class BankTransactionRuleTest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->putJson('/api/v1/bank_transaction_rules/'. $br->hashed_id, $data); + ])->putJson('/api/v1/bank_transaction_rules/'. $br->hashed_id. '?include=expense_category', $data); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); @@ -194,7 +194,7 @@ class BankTransactionRuleTest extends TestCase if($response){ $arr = $response->json(); - +nlog($arr); $response->assertStatus(200); } From eb1cac70989f2c4c401595a22945d554c797e2f7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 10:32:33 +1100 Subject: [PATCH 3/8] Tests for checking time log --- tests/Feature/TaskApiTest.php | 154 ++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index fe338e01a8f2..80e1827f5e92 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -43,6 +43,160 @@ class TaskApiTest extends TestCase Model::reguard(); } + private function checkTimeLog($log) + { + + $result = array_column($log, 0); + + asort($result); + + $new_array = []; + + foreach($result as $key => $value) + $new_array[] = $log[$key]; + + + foreach($new_array as $key => $array) + { + $next = false; + + if(count($new_array) >1 && $array[1] == 0) + return false; + + /* First test is to check if the start time is greater than the end time */ + /* Ignore the last value for now, we'll do a separate check for this */ + if($array[0] > $array[1] && $array[1] != 0){ + nlog("1"); + return false; + } + + if(array_key_exists($key+1, $new_array)){ + nlog("2"); + $next = $new_array[$key+1]; + } + + /* check the next time log and ensure the start time is GREATER than the end time of the previous record */ + if($next && $next[0] < $array[1]){ + nlog("3"); + return false; + } + + $last_row = end($new_array); + + if($last_row[1] != 0 && $last_row[0] > $last_row[1]){ + nlog($last_row[0]. " ".$last_row[1]); + nlog("4"); + return false; + } + + return true; + } + + + } + + public function testTimeLogChecker1() + { + + $log = [ + [50,0] + ]; + + $this->assertTrue($this->checkTimeLog($log)); + + } + + public function testTimeLogChecker2() + { + + $log = [ + [4,5], + [5,1] + ]; + + + $this->assertFalse($this->checkTimeLog($log)); + + } + + + public function testTimeLogChecker3() + { + + $log = [ + [4,5], + [3,50] + ]; + + + $this->assertFalse($this->checkTimeLog($log)); + + } + + + public function testTimeLogChecker4() + { + + $log = [ + [4,5], + [3,0] + ]; + + + $this->assertFalse($this->checkTimeLog($log)); + + } + + public function testTimeLogChecker5() + { + + $log = [ + [4,5], + [3,1] + ]; + + + $this->assertFalse($this->checkTimeLog($log)); + + } + + public function testTimeLogChecker6() + { + + $log = [ + [4,5], + [1,3], + ]; + + + $this->assertTrue($this->checkTimeLog($log)); + + } + + public function testTimeLogChecker7() + { + + $log = [ + [1,3], + [4,5] + ]; + + + $this->assertTrue($this->checkTimeLog($log)); + + } + + public function testTimeLogChecker8() + { + + $log = [ + [1,3], + [50,0] + ]; + + $this->assertTrue($this->checkTimeLog($log)); + + } public function testTaskListClientStatus() From ebf99689d17d4076fee5353dbd28c37d19543fd2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 10:59:36 +1100 Subject: [PATCH 4/8] Add checks for time logs --- app/Http/Requests/Request.php | 52 ++++++++++++++++++++ app/Http/Requests/Task/StoreTaskRequest.php | 3 ++ app/Http/Requests/Task/UpdateTaskRequest.php | 3 ++ tests/Feature/TaskApiTest.php | 49 +++++++++++++++--- 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 6f70dfb622aa..a26ed66e8536 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -195,4 +195,56 @@ class Request extends FormRequest public function prepareForValidation() { } + + public function checkTimeLog(array $log): bool + { + if(count($log) == 0) + return true; + + /*Get first value of all arrays*/ + $result = array_column($log, 0); + + /*Sort the array in ascending order*/ + asort($result); + + $new_array = []; + + /*Rebuild the array in order*/ + foreach($result as $key => $value) + $new_array[] = $log[$key]; + + /*Iterate through the array and perform checks*/ + foreach($new_array as $key => $array) + { + /*Flag which helps us know if there is a NEXT timelog*/ + $next = false; + /* If there are more than 1 time log in the array, ensure the last timestamp is not zero*/ + if(count($new_array) >1 && $array[1] == 0) + return false; + + /* Check if the start time is greater than the end time */ + /* Ignore the last value for now, we'll do a separate check for this */ + if($array[0] > $array[1] && $array[1] != 0) + return false; + + /* Find the next time log value - if it exists */ + if(array_key_exists($key+1, $new_array)) + $next = $new_array[$key+1]; + + /* check the next time log and ensure the start time is GREATER than the end time of the previous record */ + if($next && $next[0] < $array[1]) + return false; + + /* Get the last row of the timelog*/ + $last_row = end($new_array); + + /*If the last value is NOT zero, ensure start time is not GREATER than the endtime */ + if($last_row[1] != 0 && $last_row[0] > $last_row[1]) + return false; + + return true; + } + + } + } diff --git a/app/Http/Requests/Task/StoreTaskRequest.php b/app/Http/Requests/Task/StoreTaskRequest.php index 3b4b4171cfc6..0d0247902050 100644 --- a/app/Http/Requests/Task/StoreTaskRequest.php +++ b/app/Http/Requests/Task/StoreTaskRequest.php @@ -53,6 +53,9 @@ class StoreTaskRequest extends Request $fail('The '.$attribute.' - '.print_r($k,1).' is invalid. Unix timestamps only.'); } + if(!$this->checkTimeLog($values)) + $fail('Please correct overlapping values'); + }]; diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index 5a15cb7fd730..501861c48ed9 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -59,6 +59,9 @@ class UpdateTaskRequest extends Request $fail('The '.$attribute.' - '.print_r($k,1).' is invalid. Unix timestamps only.'); } + if(!$this->checkTimeLog($values)) + $fail('Please correct overlapping values'); + }]; return $this->globalRules($rules); diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index 80e1827f5e92..80c2b3e77097 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -55,29 +55,25 @@ class TaskApiTest extends TestCase foreach($result as $key => $value) $new_array[] = $log[$key]; - foreach($new_array as $key => $array) { $next = false; if(count($new_array) >1 && $array[1] == 0) return false; - + /* First test is to check if the start time is greater than the end time */ /* Ignore the last value for now, we'll do a separate check for this */ if($array[0] > $array[1] && $array[1] != 0){ - nlog("1"); return false; } if(array_key_exists($key+1, $new_array)){ - nlog("2"); $next = $new_array[$key+1]; } /* check the next time log and ensure the start time is GREATER than the end time of the previous record */ if($next && $next[0] < $array[1]){ - nlog("3"); return false; } @@ -85,14 +81,12 @@ class TaskApiTest extends TestCase if($last_row[1] != 0 && $last_row[0] > $last_row[1]){ nlog($last_row[0]. " ".$last_row[1]); - nlog("4"); return false; } return true; } - } public function testTimeLogChecker1() @@ -186,7 +180,7 @@ class TaskApiTest extends TestCase } - public function testTimeLogChecker8() + public function testTimeLogChecker8() { $log = [ @@ -198,6 +192,45 @@ class TaskApiTest extends TestCase } + public function testTimeLogChecker9() + { + + $log = [ + [4,5,'bb'], + [50,0,'aa'], + ]; + + $this->assertTrue($this->checkTimeLog($log)); + + } + + + + public function testTimeLogChecker10() + { + + $log = [ + [4,5,'5'], + [50,0,'3'], + ]; + + $this->assertTrue($this->checkTimeLog($log)); + + } + + + public function testTimeLogChecker11() + { + + $log = [ + [1,2,'a'], + [3,4,'d'], + ]; + + $this->assertTrue($this->checkTimeLog($log)); + + } + public function testTaskListClientStatus() { From 16b1ec62866b9a9713c6436f5c63879e11b6aba5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 11:27:38 +1100 Subject: [PATCH 5/8] Improve resolution of decimals --- app/Utils/Number.php | 10 +++++----- tests/Feature/TaskApiTest.php | 35 ++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 06edf8611ab6..e2891b7c54b9 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -223,15 +223,15 @@ class Number /* 08-01-2022 allow increased precision for unit price*/ $v = rtrim(sprintf('%f', $value), '0'); - // $precision = strlen(substr(strrchr($v, $decimal), 1)); - if ($v < 1) { + /* 08-02-2023 special if block to render $0.5 to $0.50*/ + if ($v < 1 && strlen($v) == 3) { + $precision = 2; + } + elseif ($v < 1) { $precision = strlen($v) - strrpos($v, '.') - 1; } - // if($precision == 1) - // $precision = 2; - $value = number_format($v, $precision, $decimal, $thousand); $symbol = $currency->symbol; diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index 80c2b3e77097..b5f77674024a 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -43,52 +43,57 @@ class TaskApiTest extends TestCase Model::reguard(); } - private function checkTimeLog($log) + private function checkTimeLog(array $log): bool { + if(count($log) == 0) + return true; + /*Get first value of all arrays*/ $result = array_column($log, 0); + /*Sort the array in ascending order*/ asort($result); $new_array = []; + /*Rebuild the array in order*/ foreach($result as $key => $value) $new_array[] = $log[$key]; + /*Iterate through the array and perform checks*/ foreach($new_array as $key => $array) { + /*Flag which helps us know if there is a NEXT timelog*/ $next = false; - + /* If there are more than 1 time log in the array, ensure the last timestamp is not zero*/ if(count($new_array) >1 && $array[1] == 0) return false; - /* First test is to check if the start time is greater than the end time */ + /* Check if the start time is greater than the end time */ /* Ignore the last value for now, we'll do a separate check for this */ - if($array[0] > $array[1] && $array[1] != 0){ + if($array[0] > $array[1] && $array[1] != 0) return false; - } - - if(array_key_exists($key+1, $new_array)){ + + /* Find the next time log value - if it exists */ + if(array_key_exists($key+1, $new_array)) $next = $new_array[$key+1]; - } /* check the next time log and ensure the start time is GREATER than the end time of the previous record */ - if($next && $next[0] < $array[1]){ + if($next && $next[0] < $array[1]) return false; - } + /* Get the last row of the timelog*/ $last_row = end($new_array); - - if($last_row[1] != 0 && $last_row[0] > $last_row[1]){ - nlog($last_row[0]. " ".$last_row[1]); + + /*If the last value is NOT zero, ensure start time is not GREATER than the endtime */ + if($last_row[1] != 0 && $last_row[0] > $last_row[1]) return false; - } return true; } } - + public function testTimeLogChecker1() { From 6d519431818dc55ab9956f01c4f10a6af4cb04c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 16:55:42 +1100 Subject: [PATCH 6/8] Remove postal_city as default --- app/DataMapper/CompanySettings.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index de053970f237..f269d2679c34 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -834,7 +834,6 @@ class CompanySettings extends BaseSettings '$client.address1', '$client.address2', '$client.city_state_postal', - '$client.postal_city', '$client.country', '$client.phone', '$contact.email', @@ -871,7 +870,6 @@ class CompanySettings extends BaseSettings '$company.address1', '$company.address2', '$company.city_state_postal', - '$company.postal_city', '$company.country', ], 'invoice_details' => [ From ba8cc3e44dac5bd373134b51be35fc311df9a136 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 17:06:00 +1100 Subject: [PATCH 7/8] Remove postal_city as default --- app/DataMapper/CompanySettings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index f269d2679c34..6f486c2ad9e7 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -845,7 +845,6 @@ class CompanySettings extends BaseSettings '$vendor.address1', '$vendor.address2', '$vendor.city_state_postal', - '$vendor.postal_city', '$vendor.country', '$vendor.phone', '$contact.email', From 5f9784dcf84e69c07c8ce119e7759dbdb125d42a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Feb 2023 22:37:12 +1100 Subject: [PATCH 8/8] Fixes for webhooks --- .../Requests/Webhook/StoreWebhookRequest.php | 2 + .../Requests/Webhook/UpdateWebhookRequest.php | 3 + app/Observers/ClientObserver.php | 2 +- app/Observers/InvoiceObserver.php | 2 +- tests/Feature/WebhookAPITest.php | 55 ++++++++++--------- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/app/Http/Requests/Webhook/StoreWebhookRequest.php b/app/Http/Requests/Webhook/StoreWebhookRequest.php index fcfd611979e8..9b36c4331117 100644 --- a/app/Http/Requests/Webhook/StoreWebhookRequest.php +++ b/app/Http/Requests/Webhook/StoreWebhookRequest.php @@ -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; diff --git a/app/Http/Requests/Webhook/UpdateWebhookRequest.php b/app/Http/Requests/Webhook/UpdateWebhookRequest.php index c4832e182606..21b46163a16b 100644 --- a/app/Http/Requests/Webhook/UpdateWebhookRequest.php +++ b/app/Http/Requests/Webhook/UpdateWebhookRequest.php @@ -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; diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index be5af38a02d2..de79d6c862e0 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -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); } diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 18523e49a71e..2dc5431a6fc6 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -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); } /** diff --git a/tests/Feature/WebhookAPITest.php b/tests/Feature/WebhookAPITest.php index 5f56dfc240b8..0d1708a2f34a 100644 --- a/tests/Feature/WebhookAPITest.php +++ b/tests/Feature/WebhookAPITest.php @@ -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,