Added the support for generating docs from template doc
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreatePermissionTest extends TestCase
|
||||
{
|
||||
public function test_admin_can_view_create_permission_form(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$adminRole = Role::firstOrCreate(['slug' => 'admin'], ['name' => 'Admin']);
|
||||
DB::table('role_user')->insert([
|
||||
'role_id' => $adminRole->id,
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
$this->get(route('admin.permissions.create'))
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_admin_creates_permission(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$adminRole = Role::firstOrCreate(['slug' => 'admin'], ['name' => 'Admin']);
|
||||
DB::table('role_user')->insert([
|
||||
'role_id' => $adminRole->id,
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$this->post(route('admin.permissions.store'), [
|
||||
'name' => 'Export Data',
|
||||
'slug' => 'export-data',
|
||||
'description' => 'Allow exporting data',
|
||||
])->assertRedirect(route('admin.index'));
|
||||
|
||||
$this->assertTrue(Permission::where('slug', 'export-data')->exists());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use App\Models\DocumentTemplate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Pest\Laravel; // for static analysis hints
|
||||
use function Pest\Laravel\actingAs;
|
||||
use function Pest\Laravel\get;
|
||||
use function Pest\Laravel\post;
|
||||
|
||||
it('shows index page', function () {
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('manage-settings');
|
||||
$this->actingAs($user);
|
||||
|
||||
$resp = $this->get(route('admin.document-templates.index'));
|
||||
$resp->assertSuccessful();
|
||||
});
|
||||
|
||||
it('can upload a new document template version', function () {
|
||||
Storage::fake('public');
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('manage-settings');
|
||||
$this->actingAs($user);
|
||||
|
||||
$file = UploadedFile::fake()->create('test.docx', 12, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
|
||||
|
||||
$resp = $this->post(route('admin.document-templates.store'), [
|
||||
'name' => 'Test Predloga',
|
||||
'slug' => 'test-predloga',
|
||||
'file' => $file,
|
||||
]);
|
||||
|
||||
$resp->assertRedirect();
|
||||
expect(DocumentTemplate::where('slug', 'test-predloga')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('can toggle active state', function () {
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('manage-settings');
|
||||
$this->actingAs($user);
|
||||
|
||||
$template = DocumentTemplate::factory()->create(['active' => true]);
|
||||
|
||||
$resp = $this->post(route('admin.document-templates.toggle', $template));
|
||||
$resp->assertRedirect();
|
||||
$template->refresh();
|
||||
expect($template->active)->toBeFalse();
|
||||
});
|
||||
|
||||
it('can view edit and show pages', function () {
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('manage-settings');
|
||||
$this->actingAs($user);
|
||||
$template = DocumentTemplate::factory()->create();
|
||||
|
||||
$this->get(route('admin.document-templates.show', $template))->assertSuccessful();
|
||||
$this->get(route('admin.document-templates.edit', $template))->assertSuccessful();
|
||||
});
|
||||
Reference in New Issue
Block a user