-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...internal/catalyst_voices_repositories/test/src/document/document_properties_dto_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:catalyst_voices_models/catalyst_voices_models.dart'; | ||
import 'package:catalyst_voices_repositories/src/dto/document/document_properties_dto.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(DocumentPropertiesDto, () { | ||
test('getProperty returns correct value for valid path', () { | ||
final json = { | ||
'title': 'Test Document', | ||
'content': { | ||
'text': 'This is a test.', | ||
}, | ||
'tags': ['test', 'flutter'], | ||
}; | ||
|
||
final dto = DocumentPropertiesDto.fromJson(json); | ||
final nodeId = DocumentNodeId.root.child('content').child('text'); | ||
|
||
expect(dto.getProperty(nodeId), 'This is a test.'); | ||
}); | ||
|
||
test('getProperty returns correct value for lists', () { | ||
final json = { | ||
'tags': ['test', 'flutter'], | ||
}; | ||
|
||
final dto = DocumentPropertiesDto.fromJson(json); | ||
final nodeId = DocumentNodeId.root.child('tags').child('1'); | ||
|
||
expect(dto.getProperty(nodeId), 'flutter'); | ||
}); | ||
|
||
test('getProperty returns null for invalid path', () { | ||
final json = { | ||
'title': 'Test Document', | ||
}; | ||
|
||
final dto = DocumentPropertiesDto.fromJson(json); | ||
final nodeId = DocumentNodeId.root.child('content').child('text'); | ||
|
||
expect(dto.getProperty(nodeId), isNull); | ||
}); | ||
|
||
test('getProperty returns null for invalid list index', () { | ||
final json = { | ||
'tags': ['test', 'flutter'], | ||
}; | ||
|
||
final dto = DocumentPropertiesDto.fromJson(json); | ||
final nodeId = DocumentNodeId.root.child('tags').child('invalid_index'); | ||
|
||
expect(dto.getProperty(nodeId), isNull); | ||
}); | ||
|
||
test('getProperty returns null for accessing non-collection', () { | ||
final json = { | ||
'title': 'Test Document', | ||
}; | ||
|
||
final dto = DocumentPropertiesDto.fromJson(json); | ||
final nodeId = DocumentNodeId.root.child('title').child('extra'); | ||
|
||
expect(dto.getProperty(nodeId), isNull); | ||
}); | ||
}); | ||
} |