|
194 | 194 | assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 3);
|
195 | 195 | assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]);
|
196 | 196 | });
|
| 197 | + |
| 198 | +test('restore a model in acting monitoring', function () { |
| 199 | + config()->set('user-monitoring.action_monitoring.on_restore', true); |
| 200 | + |
| 201 | + $user = createUser(); |
| 202 | + auth()->login($user); |
| 203 | + |
| 204 | + $product = \Tests\SetUp\Models\ProductSoftDelete::query()->create([ |
| 205 | + 'title' => 'milwad', |
| 206 | + 'description' => 'WE ARE HELPING TO OPEN-SOURCE WORLD' |
| 207 | + ]); |
| 208 | + |
| 209 | + $product->delete(); |
| 210 | + $product->restore(); |
| 211 | + |
| 212 | + // Assertions |
| 213 | + expect(ActionMonitoring::query()->value('table_name')) |
| 214 | + ->toBe('products') |
| 215 | + ->and(ActionMonitoring::query()->where('id', 4)->value('action_type')) |
| 216 | + ->toBe(ActionType::ACTION_RESTORED) |
| 217 | + ->and($user->name) |
| 218 | + ->toBe(ActionMonitoring::first()->user->name); |
| 219 | + |
| 220 | + // DB Assertions |
| 221 | + assertDatabaseCount('products', 1); |
| 222 | + assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 4); |
| 223 | + assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]); |
| 224 | +}); |
| 225 | + |
| 226 | +test('action not stored when the on_restore config is false', function () { |
| 227 | + $user = createUser(); |
| 228 | + auth()->login($user); |
| 229 | + |
| 230 | + $product = \Tests\SetUp\Models\ProductSoftDelete::query()->create([ |
| 231 | + 'title' => 'milwad', |
| 232 | + 'description' => 'WE ARE HELPING TO OPEN-SOURCE WORLD' |
| 233 | + ]); |
| 234 | + |
| 235 | + $product->delete(); |
| 236 | + $product->restore(); |
| 237 | + |
| 238 | + // Assertions |
| 239 | + expect(ActionMonitoring::query()->value('table_name')) |
| 240 | + ->toBe('products') |
| 241 | + ->and(ActionMonitoring::query()->where('id', 4)->value('action_type')) |
| 242 | + ->toBeNull() |
| 243 | + ->and($user->name) |
| 244 | + ->toBe(ActionMonitoring::first()->user->name); |
| 245 | + |
| 246 | + // DB Assertions |
| 247 | + assertDatabaseCount('products', 1); |
| 248 | + assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 3); |
| 249 | + assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]); |
| 250 | +}); |
0 commit comments