Files
inventree-app/test/audit_log_test.dart
T
Oliver edd7fafb6d Audit log (#899)
* Check if the backend supports auditlog info

* Change from stockhistory to auditlog

- Removes support for legacy stockhistory tracking
- Now uses AuditLog

* Update release notes
2026-10-26 20:05:38 +11:00

72 lines
1.8 KiB
Dart

/*
* Unit tests for the InvenTreeAuditLogEntry model
*/
import "package:flutter_test/flutter_test.dart";
import "package:inventree/inventree/audit_log.dart";
void main() {
group("Audit Log:", () {
test("Label", () async {
var entry = InvenTreeAuditLogEntry.fromJson({
"action": 1,
"action_label": "Update",
"event_label": null,
});
expect(entry.label, equals("Update"));
entry = InvenTreeAuditLogEntry.fromJson({
"action": 1,
"action_label": "Update",
"event_label": "Stock counted",
});
expect(entry.label, equals("Stock counted"));
});
test("Change Summary", () async {
var entry = InvenTreeAuditLogEntry.fromJson({
"changes_detail": [
{"field": "quantity", "label": "Quantity", "old": "5", "new": "10"},
{
"field": "status",
"label": "Status",
"old": 10,
"new": 50,
"old_display": "OK",
"new_display": "Attention",
},
{"field": "name", "label": "Name", "old": null, "new": "Widget"},
{"field": "notes", "label": "Notes", "old": "None", "new": "abc"},
{
"field": "tags",
"label": "Tags",
"type": "m2m",
"operation": "add",
"objects": ["red", "blue"],
},
],
});
expect(
entry.changeSummary,
equals([
"Quantity: 5 → 10",
"Status: OK → Attention",
"Name: Widget",
"Notes: abc",
"Tags: add red, blue",
]),
);
});
test("No Changes", () async {
var entry = InvenTreeAuditLogEntry.fromJson({});
expect(entry.changes, isEmpty);
expect(entry.changeSummary, isEmpty);
});
});
}