Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of defaults and serialization/deserialization of Thing Descriptions #189

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add test for unnamed ThingDescription constructor
JKRhb committed Nov 1, 2024
commit e69801593e94482223a6cb60e9a3e08b12f9ff68
68 changes: 68 additions & 0 deletions test/core/thing_description_test.dart
Original file line number Diff line number Diff line change
@@ -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": [