Skip to content

Commit

Permalink
test: add test for unnamed ThingDescription constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Nov 1, 2024
1 parent a4bd0ad commit e698015
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/core/thing_description_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,74 @@ void main() {
expect(thingDescriptionJson, thingDescription.toJson());
});

test(
"be able to be created via its constructor and converted to a "
"Map<String, dynamic>", () {
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": [
Expand Down

0 comments on commit e698015

Please sign in to comment.