Skip to content

Commit e4e00a7

Browse files
committed
add store action monitoring when a model replicate with login user test
1 parent 98e46f9 commit e4e00a7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/Feature/ActionMonitoringTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,32 @@
165165
assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 2);
166166
assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]);
167167
});
168+
169+
test('store action monitoring when a model replicate with login user', function () {
170+
config()->set('user-monitoring.action_monitoring.on_replicate', true);
171+
172+
$user = createUser();
173+
auth()->login($user);
174+
175+
$milwadPro = Product::query()->create([
176+
'title' => 'milwad',
177+
'description' => 'WE ARE HELPING TO OPEN-SOURCE WORLD'
178+
]);
179+
180+
$binafyPro = $milwadPro->replicate()->fill([
181+
'title' => 'binafy'
182+
])->save();
183+
184+
// Assertions
185+
expect(ActionMonitoring::query()->value('table_name'))
186+
->toBe('products')
187+
->and(ActionMonitoring::query()->where('id', 2)->value('action_type'))
188+
->toBe(ActionType::ACTION_REPLICATE)
189+
->and($user->name)
190+
->toBe(ActionMonitoring::first()->user->name);
191+
192+
// DB Assertions
193+
assertDatabaseCount('products', 2);
194+
assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 3);
195+
assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]);
196+
});

0 commit comments

Comments
 (0)