Skip to content

Commit

Permalink
add activity log test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cintra committed Oct 19, 2023
1 parent 7035eb2 commit be139fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stubs/modules/User/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Modules\AdminAuth\Notifications\ResetPassword;
// use Modules\Traits\ActivityLog;
// use Modules\Support\Traits\ActivityLog;
use Modules\Support\Traits\Searchable;
use Spatie\Permission\Traits\HasRoles;

Expand Down
37 changes: 37 additions & 0 deletions stubs/tests/Feature/Support/ActivityLogTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Support\Traits\ActivityLog;

uses(ActivityLog::class);

beforeEach(function () {
Schema::create('items', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->timestamps();
});
});

it('logs the activity for the model', function () {
$model = new class extends Model
{
use ActivityLog;

protected $table = 'items';

protected $guarded = [];
};

$item1 = $model->create(['name' => 'Item 1']);

$item1->delete();

$this->assertDatabaseHas('activity_log', [
'subject_id' => $item1->id,
'subject_type' => get_class($item1),
'description' => 'deleted',
]);
});

0 comments on commit be139fc

Please sign in to comment.