Skip to content

Commit 7b155dd

Browse files
committed
feat(Auditing): add threshold/prune tests
1 parent 12ded01 commit 7b155dd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Diff for: tests/Functional/AuditingTest.php

+52
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,56 @@ public function itWillAuditTheRestoredEvent()
260260
'id' => 1,
261261
], $audit->new_values, true);
262262
}
263+
264+
/**
265+
* @test
266+
*/
267+
public function itWillKeepAllAudits()
268+
{
269+
$this->app['config']->set('audit.threshold', 0);
270+
$this->app['config']->set('audit.events', [
271+
'updated',
272+
]);
273+
274+
$article = factory(Article::class)->create([
275+
'title' => 'How To Keep All Audit Records',
276+
'content' => 'N/A',
277+
'published_at' => null,
278+
'reviewed' => 0,
279+
]);
280+
281+
foreach (range(0, 100) as $count) {
282+
$article->update([
283+
'reviewed' => ($count % 2),
284+
]);
285+
}
286+
287+
$this->assertEquals(100, $article->audits()->count());
288+
}
289+
290+
/**
291+
* @test
292+
*/
293+
public function itWillRemoveOlderAuditsAboveTheThreshold()
294+
{
295+
$this->app['config']->set('audit.threshold', 10);
296+
$this->app['config']->set('audit.events', [
297+
'updated',
298+
]);
299+
300+
$article = factory(Article::class)->create([
301+
'title' => 'How To Keep The Most Recent Audit Records',
302+
'content' => 'N/A',
303+
'published_at' => null,
304+
'reviewed' => 0,
305+
]);
306+
307+
foreach (range(0, 100) as $count) {
308+
$article->update([
309+
'reviewed' => ($count % 2),
310+
]);
311+
}
312+
313+
$this->assertEquals(10, $article->audits()->count());
314+
}
263315
}

0 commit comments

Comments
 (0)