Skip to content

Commit

Permalink
chore: DocumentPropertiesDto tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed Jan 16, 2025
1 parent 68b464b commit d3e2940
Showing 1 changed file with 66 additions and 0 deletions.
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);
});
});
}

0 comments on commit d3e2940

Please sign in to comment.