Skip to content

Commit

Permalink
wip documents test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Apr 2, 2024
1 parent 84ef518 commit 7712a4a
Showing 1 changed file with 75 additions and 74 deletions.
149 changes: 75 additions & 74 deletions tests/Feature/DocumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Notification;
use Livewire;
use Livewire\Livewire;
use Tests\TestCase;

use function Pest\Livewire\livewire;

class DocumentsTest extends TestCase
{
use RefreshDatabase;
Expand All @@ -37,7 +35,6 @@ protected function getPlatformAdmins(): User
return User::factory()
->platformAdmin()
->create();

}

protected function getPlatformCoordinator(): User
Expand All @@ -53,6 +50,7 @@ protected function getOrgAdminWithActiveOrg(): Collection
->count(5)
->withRelated()
->createQuietly();

return User::query()
->withoutGlobalScopes()
->role(UserRole::ORG_ADMIN)
Expand All @@ -66,6 +64,7 @@ protected function getOrgAdminWithInactiveOrg(): Collection
->inactive()
->withRelated()
->createQuietly();

return User::query()
->withoutGlobalScopes()
->role(UserRole::ORG_ADMIN)
Expand All @@ -81,13 +80,54 @@ protected function createOrganisations(): void
->createQuietly();
}

public function testViewDocumentsWithoutUser()
public function testPlatformAdminsCanListAllDocuments(): void
{
$url = DocumentResource::getUrl('index');
$user = User::factory()
->platformAdmin()
->create();

$this->withSession(['banned' => false])
->get($url)
->assertFound();
$organisation = Organisation::factory()
->withRelated()
->createQuietly();

$documents = Document::all();

$this->actingAs($user);

Livewire::test(DocumentResource\Pages\ListDocuments::class)
->assertSuccessful()
->assertCountTableRecords(3)
->assertCanSeeTableRecords($documents)
->assertCanRenderTableColumn('name')
->filterTable('type', DocumentType::contract->value)
->assertCanSeeTableRecords($documents->where('type', DocumentType::contract))
->resetTableFilters()
->sortTable('name')
->assertCanSeeTableRecords($documents->sortBy('name'), inOrder: true)
->assertCanRenderTableColumn('organisation.name')
->sortTable('organisation.name')
->assertCanSeeTableRecords($documents->sortBy('organisation.name'), inOrder: true)
->assertCanRenderTableColumn('media.file_name')
->sortTable('media.file_name')
->assertCanSeeTableRecords($documents->sortBy('media.file_name'), inOrder: true)
->assertCanRenderTableColumn('signed_at')
->sortTable('signed_at')
->assertCanSeeTableRecords($documents->sortBy('signed_at'), inOrder: true)
->assertCanRenderTableColumn('expires_at')
->sortTable('expires_at')
->assertCanSeeTableRecords($documents->sortBy('expires_at'), inOrder: true);
}

public function testPlatformCoordinatorCanListAllDocuments(): void
{
}

public function testOrganisationAdminCanListOwnDocuments(): void
{
}

public function testOrganisationAdminCannotListOtherDocuments(): void
{
}

public function testViewDocumentsByOrgAdmin(): void
Expand Down Expand Up @@ -130,18 +170,6 @@ public function testViewDocumentsByPlatformAdmin(): void
->assertSuccessful();
}

public function testViewDocumentWithoutUser()
{
$this->createOrganisations();
$document = Document::query()
->inRandomOrder()
->first();

$url = DocumentResource::getUrl('view', ['record' => $document->id]);
$this->withSession(['banned' => false])
->get($url)
->assertFound();
}

public function testViewDocumentByPlatformAdmin(): void
{
Expand Down Expand Up @@ -236,19 +264,6 @@ public function testViewDocumentByAnotherInactiveOrgAdmin(): void
->assertFound();
}

public function testEditDocumentWithoutUser()
{
$this->createOrganisations();
$document = Document::query()
->inRandomOrder()
->first();

$url = DocumentResource::getUrl('edit', ['record' => $document->id]);
$this->withSession(['banned' => false])
->get($url)
->assertFound();
}

public function testEditDocumentByPlatformAdmin(): void
{
$this->createOrganisations();
Expand Down Expand Up @@ -342,18 +357,6 @@ public function testEditDocumentByAnotherInactiveOrgAdmin(): void
->assertFound();
}

public function testDeleteDocumentWithoutUser()
{
$this->assertTrue(true);
// $this->createOrganisations();
// $document = Document::query()
// ->inRandomOrder()
// ->first();
//
// \Livewire::test(DocumentResource\Pages\ViewDocument::class, ['record' => $document->id])
// ->assertPageActionDisabled('delete');
}

public function testDeleteDocumentByPlatformAdmin(): void
{
$this->createOrganisations();
Expand Down Expand Up @@ -411,37 +414,37 @@ public function testDeleteDocumentByAnotherOrgAdmin(): void
{
$this->assertTrue(true);

// $orgAdmins = $this->getOrgAdminWithActiveOrg();
//
// $document = Document::query()
// ->inRandomOrder()
// ->first();
//
// $documentUser = $orgAdmins->filter(fn($item) => $item->organisation_id != $document->organisation_id)->first();
// $params = ['record' => $document->id];
//
// \Livewire::actingAs($documentUser);
// \Livewire::test(DocumentResource\Pages\ViewDocument::class, $params)
// ->assertPageActionDisabled('delete');
// $orgAdmins = $this->getOrgAdminWithActiveOrg();
//
// $document = Document::query()
// ->inRandomOrder()
// ->first();
//
// $documentUser = $orgAdmins->filter(fn($item) => $item->organisation_id != $document->organisation_id)->first();
// $params = ['record' => $document->id];
//
// \Livewire::actingAs($documentUser);
// \Livewire::test(DocumentResource\Pages\ViewDocument::class, $params)
// ->assertPageActionDisabled('delete');
}

public function testDeleteDocumentByAnotherInactiveOrgAdmin(): void
{
$this->assertTrue(true);

// $orgAdmins = $this->getOrgAdminWithInactiveOrg();
//
// $document = Document::query()
// ->inRandomOrder()
// ->first();
//
// $url = DocumentResource::getUrl('edit', ['record' => $document->id]);
//
// $documentUser = $orgAdmins->filter(fn($item) => $item->organisation_id != $document->organisation_id)->first();
// $params = ['record' => $document->id];
// \Livewire::actingAs($documentUser);
// \Livewire::test(DocumentResource\Pages\ViewDocument::class, $params)
// ->assertPageActionDisabled('delete');
// $orgAdmins = $this->getOrgAdminWithInactiveOrg();
//
// $document = Document::query()
// ->inRandomOrder()
// ->first();
//
// $url = DocumentResource::getUrl('edit', ['record' => $document->id]);
//
// $documentUser = $orgAdmins->filter(fn($item) => $item->organisation_id != $document->organisation_id)->first();
// $params = ['record' => $document->id];
// \Livewire::actingAs($documentUser);
// \Livewire::test(DocumentResource\Pages\ViewDocument::class, $params)
// ->assertPageActionDisabled('delete');
}

public function testCreateDocumentByPlatformAdmin(): void
Expand Down Expand Up @@ -476,7 +479,6 @@ public function testCreateDocumentByInactiveOrgAdmin()
->assertForbidden();
}


public function testCreateDocument()
{
$this->createOrganisations();
Expand Down Expand Up @@ -560,7 +562,7 @@ public function testCreateDocument()
'document' => [$file]])
->call('create')
->assertHasFormErrors(['signed_at' => 'required',
'expires_at' => 'required'
'expires_at' => 'required',
]);

// document type protocol with never expires and without start/end date
Expand Down Expand Up @@ -615,5 +617,4 @@ public function testCreateDocument()
->call('create')
->assertHasFormErrors(['expires_at']);
}

}

0 comments on commit 7712a4a

Please sign in to comment.