first commit

This commit is contained in:
Noor E Ilahi
2026-01-09 12:54:53 +05:30
commit 7ccf44f7da
1070 changed files with 113036 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\Invitation;
use App\Models\User;
use Tests\Facades\UserFactory;
use Tests\TestCase;
class CountTest extends TestCase
{
private const URI = 'invitations/count';
private User $admin;
private User $user;
protected function setUp(): void
{
parent::setUp();
$this->user = UserFactory::withTokens()->asUser()->create();
$this->admin = UserFactory::withTokens()->asAdmin()->create();
}
public function test_count_as_admin(): void
{
$response = $this->actingAs($this->admin)->getJson(self::URI);
$response->assertOk();
$response->assertJson(['total' => Invitation::count()]);
}
public function test_count_as_user(): void
{
$response = $this->actingAs($this->user)->getJson(self::URI);
$response->assertForbidden();
}
public function test_unauthorized(): void
{
$response = $this->getJson(self::URI);
$response->assertUnauthorized();
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\User;
use App\Models\invitation;
use Tests\Facades\UserFactory;
use Tests\Facades\InvitationFactory;
use Tests\TestCase;
class CreateTest extends TestCase
{
private const URI = 'invitations/create';
private User $admin;
private User $manager;
private User $auditor;
private User $user;
private array $invitationRequestData;
private array $invitationModelData;
protected function setUp(): void
{
parent::setUp();
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
$this->invitationRequestData = InvitationFactory::createRequestData();
$this->invitationModelData = InvitationFactory::createRandomModelData();
}
public function test_create_as_admin(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->invitationRequestData);
$response->assertOk();
$this->assertDatabaseHas((new Invitation)->getTable(), $this->invitationRequestData['users'][0]);
foreach ($response->json('res') as $invitation) {
$this->assertDatabaseHas((new Invitation)->getTable(), $invitation);
}
}
public function test_create_as_manager(): void
{
$response = $this->actingAs($this->manager)->postJson(self::URI, $this->invitationRequestData);
$response->assertForbidden();
}
public function test_create_as_auditor(): void
{
$response = $this->actingAs($this->auditor)->postJson(self::URI, $this->invitationRequestData);
$response->assertForbidden();
}
public function test_create_as_user(): void
{
$response = $this->actingAs($this->user)->postJson(self::URI, $this->invitationRequestData);
$response->assertForbidden();
}
public function test_create_already_exists(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->invitationRequestData);
$this->assertDatabaseHas((new Invitation)->getTable(), $response->decodeResponseJson()['res'][0]);
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->invitationRequestData);
$response->assertValidationError();
}
public function test_unauthorized(): void
{
$response = $this->postJson(self::URI);
$response->assertUnauthorized();
}
public function test_without_params(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI);
$response->assertValidationError();
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\invitation;
use App\Models\User;
use Tests\Facades\UserFactory;
use Tests\TestCase;
class ListTest extends TestCase
{
private const URI = 'invitations/list';
private User $admin;
private User $manager;
private User $auditor;
private User $user;
protected function setUp(): void
{
parent::setUp();
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
}
public function test_list_as_admin(): void
{
$response = $this->actingAs($this->admin)->getJson(self::URI);
$invitations = invitation::all()->toArray();
$response->assertJson($invitations);
}
public function test_list_as_manager(): void
{
$response = $this->actingAs($this->manager)->getJson(self::URI);
$response->assertForbidden();
}
public function test_list_as_auditor(): void
{
$response = $this->actingAs($this->auditor)->getJson(self::URI);
$response->assertForbidden();
}
public function test_list_as_user(): void
{
$response = $this->actingAs($this->user)->getJson(self::URI);
$response->assertForbidden();
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\User;
use App\Models\invitation;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\Facades\UserFactory;
use Tests\Facades\InvitationFactory;
use Tests\TestCase;
class RemoveTest extends TestCase
{
use WithFaker;
private const URI = 'invitations/remove';
private User $admin;
private User $manager;
private User $auditor;
private User $user;
private invitation $invitation;
protected function setUp(): void
{
parent::setUp();
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
$this->invitation = InvitationFactory::create();
}
public function test_remove_as_admin(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->invitation->only('id'));
$response->assertOk();
$this->assertDeleted((new Invitation)->getTable(), $this->invitation->only('id'));
}
public function test_remove_as_manager(): void
{
$response = $this->actingAs($this->manager)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_remove_as_auditor(): void
{
$response = $this->actingAs($this->auditor)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_not_existing(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, ['id' => $this->faker->randomNumber()]);
$response->assertValidationError();
}
public function test_remove_as_user(): void
{
$response = $this->actingAs($this->user)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_unauthorized(): void
{
$response = $this->postJson(self::URI);
$response->assertUnauthorized();
}
public function test_without_params(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI);
$response->assertValidationError();
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\User;
use App\Models\Invitation;
use Tests\Facades\UserFactory;
use Tests\Facades\InvitationFactory;
use Tests\TestCase;
class ResendTest extends TestCase
{
private const URI = 'invitations/resend';
private User $admin;
private User $manager;
private User $auditor;
private User $user;
private Invitation $invitation;
protected function setUp(): void
{
parent::setUp();
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
$this->invitation = InvitationFactory::create();
}
public function test_resend_as_admin(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, ['id' => $this->invitation->id]);
$response->assertOk();
$response->assertNotEquals(
$response->decodeResponseJson()['res']['expires_at'],
$this->invitation->expires_at->toISOString()
);
}
public function test_resend_as_manager(): void
{
$response = $this->actingAs($this->manager)->postJson(self::URI, ['id' => $this->invitation->id]);
$response->assertForbidden();
}
public function test_resend_as_auditor(): void
{
$response = $this->actingAs($this->auditor)->postJson(self::URI, ['id' => $this->invitation->id]);
$response->assertForbidden();
}
public function test_resend_as_user(): void
{
$response = $this->actingAs($this->user)->postJson(self::URI, ['id' => $this->invitation->id]);
$response->assertForbidden();
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Tests\Feature\Invitations;
use App\Models\User;
use App\Models\Invitation;
use Tests\Facades\InvitationFactory;
use Tests\Facades\UserFactory;
use Tests\TestCase;
class ShowTest extends TestCase
{
private const URI = 'invitations/show';
private User $admin;
private User $manager;
private User $auditor;
private User $user;
private Invitation $invitation;
protected function setUp(): void
{
parent::setUp();
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
$this->invitation = InvitationFactory::create();
}
public function test_show_as_admin(): void
{
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->invitation->only('id'));
$response->assertOk();
$response->assertJson($this->invitation->toArray());
}
public function test_show_as_manager(): void
{
$response = $this->actingAs($this->manager)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_show_as_auditor(): void
{
$response = $this->actingAs($this->auditor)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_show_as_user(): void
{
$response = $this->actingAs($this->user)->postJson(self::URI, $this->invitation->only('id'));
$response->assertForbidden();
}
public function test_unauthorized(): void
{
$response = $this->postJson(self::URI);
$response->assertUnauthorized();
}
}