diff --git a/test/widget_test.dart b/test/widget_test.dart index ae0761c..531745d 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -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': [], + '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': [], + '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); + }); + }); }