Skip to content

Commit

Permalink
test: improve ConsumedThing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 4, 2024
1 parent 270d1b9 commit 4552ad6
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions test/core/consumed_thing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import "package:dart_wot/src/definitions/validation/validation_exception.dart";
import "package:test/test.dart";

void main() {
group("Consumed Thing Tests", () {
setUp(() {
// Additional setup goes here.
});

test("Parse Interaction Affordances", () async {
group("ConsumedThing should", () {
test("parse Interaction Affordances", () async {
const thingDescriptionJson = {
"@context": [
"https://www.w3.org/2022/wot/td/v1.1",
Expand Down Expand Up @@ -219,7 +215,7 @@ void main() {
});

test(
"Use of URI Template Variables",
"use URI Template Variables",
() async {
const thingDescriptionJson = {
"@context": ["http://www.w3.org/ns/td"],
Expand Down Expand Up @@ -279,4 +275,50 @@ void main() {
},
skip: true, // TODO: Replace with test with local server
);

test("throw ArgumentErrors for missing Affordances", () async {
const thingDescriptionJson = {
"@context": "https://www.w3.org/2022/wot/td/v1.1",
"title": "Test Thing",
"securityDefinitions": {
"nosec_sc": {"scheme": "nosec"},
},
"security": "nosec_sc",
};

final parsedTd = ThingDescription.fromJson(thingDescriptionJson);

final servient = Servient();
final wot = await servient.start();

final consumedThing = await wot.consume(parsedTd);

expect(
() async => await consumedThing.readProperty("test"),
throwsArgumentError,
);

expect(
() async => await consumedThing.writeProperty(
"test",
null.asInteractionInput(),
),
throwsArgumentError,
);

expect(
() async => await consumedThing.observeProperty("test", (_) => ()),
throwsArgumentError,
);

expect(
() async => await consumedThing.invokeAction("test"),
throwsArgumentError,
);

expect(
() async => await consumedThing.subscribeEvent("test", (_) => ()),
throwsArgumentError,
);
});
}

0 comments on commit 4552ad6

Please sign in to comment.