Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
chore: disable throttle-request middleware on api tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
  • Loading branch information
feryardiant committed Apr 1, 2024
1 parent 9070613 commit e07ab59
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/Feature/Http/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Creasi\Base\Database\Models\Address;
use Creasi\Tests\Feature\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand Down Expand Up @@ -31,6 +32,8 @@ class AddressTest extends TestCase
#[Test]
public function should_receive_404_when_no_data_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->getJson($this->getRoutePath());
Expand All @@ -41,6 +44,8 @@ public function should_receive_404_when_no_data_available(): void
#[Test]
public function should_able_to_retrieve_all_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$model = Address::factory()->createOne();
Expand All @@ -58,6 +63,8 @@ public function should_able_to_retrieve_all_data(): void
#[Test]
public function should_able_to_store_new_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$data = Address::factory()->raw();
Expand All @@ -73,6 +80,8 @@ public function should_able_to_store_new_data(): void
#[Test]
public function should_able_to_show_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$model = Address::factory()->createOne();
Expand All @@ -89,6 +98,8 @@ public function should_able_to_show_existing_data(): void
#[Test]
public function should_able_to_update_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Address::factory()->createOne();
Expand All @@ -104,6 +115,8 @@ public function should_able_to_update_existing_data(): void
#[Test]
public function should_able_to_delete_and_restore_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$model = Address::factory()->createOne();
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Http/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Creasi\Base\Enums\StakeholderType;
use Creasi\Tests\Feature\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
Expand All @@ -33,6 +34,8 @@ class CompanyTest extends TestCase
#[Test]
public function should_receive_404_when_no_data_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->getJson($this->getRoutePath());
Expand All @@ -43,6 +46,8 @@ public function should_receive_404_when_no_data_available(): void
#[Test]
public function should_able_to_retrieve_all_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$external = Organization::factory()->createOne(['name' => 'Internal Company']);
Expand All @@ -61,6 +66,8 @@ public function should_able_to_retrieve_all_data(): void
#[Test]
public function should_able_to_store_new_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$data = Organization::factory()->raw();
Expand All @@ -76,6 +83,8 @@ public function should_able_to_store_new_data(): void
#[Test]
public function should_able_to_show_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->createOne();
Expand All @@ -91,6 +100,8 @@ public function should_able_to_show_existing_data(): void
#[Test]
public function should_receive_404_when_no_addresses_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->createOne();
Expand All @@ -103,6 +114,8 @@ public function should_receive_404_when_no_addresses_available(): void
#[Test]
public function should_able_to_create_new_address(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$data = Address::factory()->raw();
Expand All @@ -116,6 +129,8 @@ public function should_able_to_create_new_address(): void
#[Test]
public function should_able_to_retrieve_all_addresses(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->withAddress()->createOne();
Expand All @@ -128,6 +143,8 @@ public function should_able_to_retrieve_all_addresses(): void
#[Test]
public function should_receive_404_when_no_files_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->createOne();
Expand All @@ -140,6 +157,8 @@ public function should_receive_404_when_no_files_available(): void
#[Test]
public function should_able_to_upload_and_store_new_file(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Storage::fake();
Sanctum::actingAs($this->user());

Expand All @@ -156,6 +175,8 @@ public function should_able_to_upload_and_store_new_file(): void
#[Test]
public function should_able_to_retrieve_all_uploaded_files(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->withFileUpload(FileType::Document)->createOne();
Expand All @@ -168,6 +189,8 @@ public function should_able_to_retrieve_all_uploaded_files(): void
#[Test]
public function should_able_to_update_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->createOne();
Expand All @@ -183,6 +206,8 @@ public function should_able_to_update_existing_data(): void
#[Test]
public function should_able_to_delete_and_restore_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Organization::factory()->createOne();
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/Http/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Creasi\Base\Enums\FileType;
use Creasi\Tests\Feature\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -19,6 +20,8 @@ class FileUploadTest extends TestCase
#[Test]
public function should_receive_404_when_no_data_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->getJson($this->getRoutePath());
Expand All @@ -29,6 +32,8 @@ public function should_receive_404_when_no_data_available(): void
#[Test]
public function should_able_to_retrieve_all_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$user->profile->storeFile(FileType::Document, '/doc/file.pdf', 'document');
Expand All @@ -41,6 +46,8 @@ public function should_able_to_retrieve_all_data(): void
#[Test]
public function should_able_to_store_new_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$data = File::factory()->raw();
Expand All @@ -55,6 +62,8 @@ public function should_able_to_store_new_data(): void
#[Test]
public function should_able_to_show_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$model = $user->profile->storeFile(FileType::Document, '/doc/file.pdf', 'document');
Expand All @@ -67,6 +76,8 @@ public function should_able_to_show_existing_data(): void
#[Test]
public function should_able_to_update_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = File::factory()->createOne();
Expand All @@ -79,6 +90,8 @@ public function should_able_to_update_existing_data(): void
#[Test]
public function should_able_to_delete_and_restore_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$model = $user->profile->storeFile(FileType::Document, '/doc/file.pdf', 'document');
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/Http/PersonnelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Creasi\Base\Enums\FileType;
use Creasi\Tests\Feature\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
Expand All @@ -32,6 +33,8 @@ class PersonnelTest extends TestCase
#[Test]
public function should_able_to_retrieve_all_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());
Person::factory(2)->create();

Expand All @@ -47,6 +50,8 @@ public function should_able_to_retrieve_all_data(): void
#[Test]
public function should_able_to_store_new_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());
$data = Person::factory()->raw();

Expand All @@ -61,6 +66,8 @@ public function should_able_to_store_new_data(): void
#[Test]
public function should_able_to_show_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -76,6 +83,8 @@ public function should_able_to_show_existing_data(): void
#[Test]
public function should_receive_404_when_no_addresses_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -88,6 +97,8 @@ public function should_receive_404_when_no_addresses_available(): void
#[Test]
public function should_able_to_create_new_address(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -101,6 +112,8 @@ public function should_able_to_create_new_address(): void
#[Test]
public function should_able_to_retrieve_all_addresses(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -115,6 +128,8 @@ public function should_able_to_retrieve_all_addresses(): void
#[Test]
public function should_receive_404_when_no_files_available(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -127,6 +142,8 @@ public function should_receive_404_when_no_files_available(): void
#[Test]
public function should_able_to_upload_and_store_new_file(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Storage::fake();
Sanctum::actingAs($this->user());

Expand All @@ -143,6 +160,8 @@ public function should_able_to_upload_and_store_new_file(): void
#[Test]
public function should_able_to_retrieve_all_uploaded_files(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->withFileUpload(FileType::Document)->createOne();
Expand All @@ -155,6 +174,8 @@ public function should_able_to_retrieve_all_uploaded_files(): void
#[Test]
public function should_able_to_update_existing_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand All @@ -170,6 +191,8 @@ public function should_able_to_update_existing_data(): void
#[Test]
public function should_able_to_delete_and_restore_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$model = Person::factory()->createOne();
Expand Down
5 changes: 5 additions & 0 deletions tests/Feature/Http/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Creasi\Tests\Feature\Http;

use Creasi\Tests\Feature\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand Down Expand Up @@ -34,6 +35,8 @@ class ProfileTest extends TestCase
#[Test]
public function should_able_to_retrieve_profile_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->getJson($this->getRoutePath());
Expand All @@ -44,6 +47,8 @@ public function should_able_to_retrieve_profile_data(): void
#[Test]
public function should_able_to_update_profile_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($user = $this->user());

$user->load('profile');
Expand Down
5 changes: 5 additions & 0 deletions tests/Feature/Http/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Creasi\Tests\Feature\Http;

use Creasi\Tests\Feature\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Laravel\Sanctum\Sanctum;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -17,6 +18,8 @@ class SettingTest extends TestCase
#[Test]
public function should_able_to_retrieve_setting_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->getJson($this->getRoutePath());
Expand All @@ -27,6 +30,8 @@ public function should_able_to_retrieve_setting_data(): void
#[Test]
public function should_able_to_update_setting_data(): void
{
$this->withoutMiddleware(ThrottleRequests::class);

Sanctum::actingAs($this->user());

$response = $this->putJson($this->getRoutePath());
Expand Down
Loading

0 comments on commit e07ab59

Please sign in to comment.