refactor: improve activity log tests by directly asserting causer and properties instead of relying on database retrieval
This commit is contained in:
parent
bae9e59194
commit
bed9113269
@ -212,21 +212,20 @@ function createActivityLogs(User $causer, int $count = 3): void
|
||||
test('activity log stores causer information', function () {
|
||||
$user = createActivityLogUserWithPermission(PermissionEnum::ACTIVITY_LOGS_VIEW);
|
||||
|
||||
activity()
|
||||
$activity = activity()
|
||||
->causedBy($user)
|
||||
->event('created')
|
||||
->log('Test log entry');
|
||||
|
||||
$activity = Activity::latest()->first();
|
||||
|
||||
expect($activity->causer_type)->toBe(User::class);
|
||||
expect($activity->causer_id)->toBe($user->id);
|
||||
expect($activity)->not->toBeNull();
|
||||
expect($activity->causer)->not->toBeNull();
|
||||
expect($activity->causer->id)->toBe($user->id);
|
||||
});
|
||||
|
||||
test('activity log stores properties correctly', function () {
|
||||
$user = createActivityLogUserWithPermission(PermissionEnum::ACTIVITY_LOGS_VIEW);
|
||||
|
||||
activity()
|
||||
$activity = activity()
|
||||
->causedBy($user)
|
||||
->event('updated')
|
||||
->withProperties([
|
||||
@ -235,9 +234,11 @@ function createActivityLogs(User $causer, int $count = 3): void
|
||||
])
|
||||
->log('Test with properties');
|
||||
|
||||
$activity = Activity::latest()->first();
|
||||
expect($activity)->not->toBeNull();
|
||||
|
||||
expect($activity->properties->get('attributes')['name'])->toBe('New Value');
|
||||
expect($activity->properties->get('old')['name'])->toBe('Old Value');
|
||||
$props = $activity->properties ?? $activity->attribute_changes;
|
||||
expect($props)->not->toBeNull();
|
||||
expect($props->get('attributes')['name'])->toBe('New Value');
|
||||
expect($props->get('old')['name'])->toBe('Old Value');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user