From 8d225288ed85d37496da6d51bc231a3f0afcd1a0 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 1 Nov 2024 10:41:45 +0100 Subject: [PATCH] test: add test for unnamed ThingDescription constructor --- test/core/thing_description_test.dart | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/core/thing_description_test.dart b/test/core/thing_description_test.dart index 20c72926..19cbc762 100644 --- a/test/core/thing_description_test.dart +++ b/test/core/thing_description_test.dart @@ -39,6 +39,74 @@ void main() { expect(thingDescriptionJson, thingDescription.toJson()); }); + test( + "be able to created via its constructor " + "and converted to a Map", () { + const thingDescriptionJson = { + "@context": [ + "https://www.w3.org/2022/wot/td/v1.1", + {"@language": "de"}, + ], + "title": "Test Thing", + "securityDefinitions": { + "nosec_sc": {"scheme": "nosec"}, + }, + "security": ["nosec_sc"], + "properties": { + "status": { + "type": "string", + "readOnly": true, + "observable": true, + "forms": [ + { + "href": "https://example.org", + "contentType": "application/cbor", + } + ], + }, + }, + }; + + final thingDescription = ThingDescription( + context: Context( + [ + SingleContextEntry( + Uri.parse("https://www.w3.org/2022/wot/td/v1.1"), + ), + const StringMapContextEntry( + "@language", + "de", + ), + ], + ), + title: "Test Thing", + security: const [ + "nosec_sc", + ], + securityDefinitions: const { + "nosec_sc": NoSecurityScheme(), + }, + properties: { + "status": Property( + forms: [ + Form( + Uri.parse("https://example.org"), + contentType: "application/cbor", + ), + ], + observable: true, + dataSchema: const DataSchema( + type: "string", + readOnly: true, + writeOnly: false, + ), + ), + }, + ); + + expect(thingDescriptionJson, thingDescription.toJson()); + }); + test("throw a FormatException when it is invalid during parsing", () { const thingDescriptionJson = { "@context": [