Skip to content

Commit

Permalink
fixup! test: add tests for exploreDirectory method
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 22, 2023
1 parent 7565ff9 commit 5eda27d
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions test/core/discovery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,59 @@ final directoryThingDescription1 = '''
const invalidTestThingDescription = '"Hi there!"';

void main() {
group('Discovery Tests', () {
group('requestThingDescription()', () {
test('should be able to retrieve a valid TD', () async {
final servient = Servient(
clientFactories: [
_MockedProtocolClientFactory(),
],
);
group('requestThingDescription()', () {
test('should be able to retrieve a valid TD', () async {
final servient = Servient(
clientFactories: [
_MockedProtocolClientFactory(),
],
);

final wot = await servient.start();
final thingDescription =
await wot.requestThingDescription(validTestDiscoveryUri);
final wot = await servient.start();
final thingDescription =
await wot.requestThingDescription(validTestDiscoveryUri);

expect(thingDescription.title, validTestTitle);
});

test(
'should throw an exception when an invalid TD is retrieved',
() async {
final servient = Servient(
clientFactories: [
_MockedProtocolClientFactory(),
],
);

final wot = await servient.start();
await expectLater(
wot.requestThingDescription(invalidTestDiscoveryUri),
// TODO: Refine error handling
throwsA(isA<DiscoveryException>()),
);
},
);
expect(thingDescription.title, validTestTitle);
});
group('exploreDirectory()', () {
test('should be able to discover valid TDs from a TD directory',
() async {

test(
'should throw an exception when an invalid TD is retrieved',
() async {
final servient = Servient(
clientFactories: [
_MockedProtocolClientFactory(),
],
);

final wot = await servient.start();
final thingDiscoveryProcess =
await wot.exploreDirectory(directoryTestUri1);
await expectLater(
wot.requestThingDescription(invalidTestDiscoveryUri),
// TODO: Refine error handling
throwsA(isA<DiscoveryException>()),
);
},
);
});

var counter = 0;
await for (final thingDescription in thingDiscoveryProcess) {
counter++;
expect(thingDescription.title, validTestTitle);
}
expect(counter, 1);
expect(thingDiscoveryProcess.done, true);
});
group('exploreDirectory()', () {
test('should be able to discover valid TDs from a TD directory', () async {
final servient = Servient(
clientFactories: [
_MockedProtocolClientFactory(),
],
);

final wot = await servient.start();
final thingDiscoveryProcess =
await wot.exploreDirectory(directoryTestUri1);

var counter = 0;
await for (final thingDescription in thingDiscoveryProcess) {
counter++;
expect(thingDescription.title, validTestTitle);
}
expect(counter, 1);
expect(thingDiscoveryProcess.done, true);
});
});
}
Expand Down

0 comments on commit 5eda27d

Please sign in to comment.