diff --git a/tests/Functional/AuditingTest.php b/tests/Functional/AuditingTest.php index 6f55abc2..3c3f8c9f 100644 --- a/tests/Functional/AuditingTest.php +++ b/tests/Functional/AuditingTest.php @@ -620,6 +620,7 @@ public function itWillAuditSync() $article->auditSync('categories', [$secondCategory->getKey()]); + $audit = $article->audits()->where('event', 'sync')->latest()->first(); $no_of_audits_after = Audit::where('auditable_type', Article::class)->count(); $categoryAfter = $article->categories()->first()->getKey(); @@ -627,6 +628,38 @@ public function itWillAuditSync() $this->assertSame($secondCategory->getKey(), $categoryAfter); $this->assertNotSame($categoryBefore, $categoryAfter); $this->assertGreaterThan($no_of_audits_before, $no_of_audits_after); + $this->assertCount(1, $audit->old_values['categories']); + $this->assertCount(1, $audit->new_values['categories']); + } + + /** + * @test + * @return void + */ + public function itWillAuditSyncAddAndRemove() + { + $firstCategory = factory(Category::class)->create(); + $secondCategory = factory(Category::class)->create(); + $thirdCategory = factory(Category::class)->create(); + $article = factory(Article::class)->create(); + + $article->categories()->attach([$firstCategory->getKey(), $secondCategory->getKey()]); + + $no_of_audits_before = Audit::where('auditable_type', Article::class)->count(); + + $article->auditSync('categories', [$secondCategory->getKey(), $thirdCategory->getKey()]); + + $audit = $article->audits()->where('event', 'sync')->latest()->first(); + $no_of_audits_after = Audit::where('auditable_type', Article::class)->count(); + + $attachedCategories = $article->categories()->pluck('id')->toArray(); + + $this->assertNotContains($firstCategory->getKey(), $attachedCategories); + $this->assertContains($secondCategory->getKey(), $attachedCategories); + $this->assertContains($thirdCategory->getKey(), $attachedCategories); + $this->assertGreaterThan($no_of_audits_before, $no_of_audits_after); + $this->assertCount(1, $audit->old_values['categories']); + $this->assertCount(2, $audit->new_values['categories']); } /**