From 7b2a9d81fc874be5012f710094976992a124aa4a Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 30 Dec 2023 03:56:17 +0100 Subject: [PATCH] test: improve ContentSerdes tests --- test/core/content_serdes_test.dart | 41 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/test/core/content_serdes_test.dart b/test/core/content_serdes_test.dart index 180ade75..8b556f85 100644 --- a/test/core/content_serdes_test.dart +++ b/test/core/content_serdes_test.dart @@ -17,8 +17,8 @@ Content _getTestContent(String input) { } void main() { - group('Content Serdes Tests', () { - test('Content Validation', () async { + group('ContentSerdes should', () { + test('validate Content', () async { final contentSerdes = ContentSerdes(); final testContent1 = _getTestContent('42'); @@ -57,7 +57,7 @@ void main() { null, ); }); - test('Codec Registration', () async { + test('support registration of new Codecs', () async { final contentSerdes = ContentSerdes(); expect( @@ -130,5 +130,40 @@ void main() { throwsArgumentError, ); }); + + test('return a Content object with an empty Stream for undefined values', + () async { + final contentSerdes = ContentSerdes(); + final content = contentSerdes.valueToContent(null, null); + + expect(await content.body.isEmpty, isTrue); + }); + + test('reject undefined DataSchemaValues if a DataSchema is given', + () async { + final contentSerdes = ContentSerdes(); + + expect( + () => contentSerdes.valueToContent( + null, + // FIXME(JKRhb): Should not be necessary to use fromJson here + DataSchema.fromJson({'type': 'object'}, PrefixMapping()), + ), + throwsA(isA()), + ); + }); + + test('convert DataSchemaValues to Content', () async { + final contentSerdes = ContentSerdes(); + const inputValue = 'foo'; + + final content = contentSerdes.valueToContent( + DataSchemaValue.fromString(inputValue), + null, + ); + + expect(await content.toByteList(), [34, 102, 111, 111, 34]); + expect(content.type, 'application/json'); + }); }); }