test: add KnowledgeItem model unit tests

This commit is contained in:
2026-04-04 23:40:29 -04:00
parent deec2318f7
commit 535833abfe
+36
View File
@@ -1,3 +1,4 @@
import 'package:fabled_app/data/models/knowledge_item.dart';
import 'package:fabled_app/data/models/note.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -30,4 +31,39 @@ void main() {
expect(note.noteType, equals('note'));
});
});
group('KnowledgeItem.fromJson', () {
test('parses a task item with task fields', () {
final json = {
'id': 10,
'note_type': 'task',
'title': 'Do the thing',
'body': '',
'tags': <dynamic>[],
'status': 'todo',
'priority': 'high',
'due_date': '2025-01-01',
'created_at': '2024-01-01T00:00:00',
'updated_at': '2024-01-01T00:00:00',
};
final item = KnowledgeItem.fromJson(json);
expect(item.noteType, equals('task'));
expect(item.status, equals('todo'));
expect(item.priority, equals('high'));
});
test('defaults noteType to note when absent', () {
final json = {
'id': 11,
'title': 'A note',
'body': '',
'tags': <dynamic>[],
'created_at': '2024-01-01T00:00:00',
'updated_at': '2024-01-01T00:00:00',
};
final item = KnowledgeItem.fromJson(json);
expect(item.noteType, equals('note'));
expect(item.status, isNull);
});
});
}