from django.test import TestCase

from core.models import AuditLog
from inventory.models import Category


class AuditLogSignalTests(TestCase):
    def test_create_update_delete_are_logged(self):
        category = Category.objects.create(name='Stationery')
        category.description = 'School supplies'
        category.save()
        category.delete()

        logs = AuditLog.objects.filter(app_label='inventory', model_name='category')
        actions = list(logs.values_list('action', flat=True))

        self.assertIn(AuditLog.Action.CREATE, actions)
        self.assertIn(AuditLog.Action.UPDATE, actions)
        self.assertIn(AuditLog.Action.DELETE, actions)
