70 lines
1.9 KiB
Dart
70 lines
1.9 KiB
Dart
import 'package:fabled_app/data/models/knowledge_item.dart';
|
|
import 'package:fabled_app/data/models/note.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('Note.fromJson', () {
|
|
test('parses noteType when present', () {
|
|
final json = {
|
|
'id': 1,
|
|
'title': 'Alice',
|
|
'body': '',
|
|
'tags': <dynamic>[],
|
|
'note_type': 'person',
|
|
'created_at': '2024-01-01T00:00:00',
|
|
'updated_at': '2024-01-01T00:00:00',
|
|
};
|
|
final note = Note.fromJson(json);
|
|
expect(note.noteType, equals('person'));
|
|
});
|
|
|
|
test('defaults noteType to note when absent', () {
|
|
final json = {
|
|
'id': 2,
|
|
'title': 'My note',
|
|
'body': '',
|
|
'tags': <dynamic>[],
|
|
'created_at': '2024-01-01T00:00:00',
|
|
'updated_at': '2024-01-01T00:00:00',
|
|
};
|
|
final note = Note.fromJson(json);
|
|
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);
|
|
});
|
|
});
|
|
}
|