Skip to content

Commit 2feb002

Browse files
committed
test: add tests for Content class
1 parent 5c495b4 commit 2feb002

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/core/content_test.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import 'dart:convert';
8+
9+
import 'package:dart_wot/dart_wot.dart';
10+
import 'package:dart_wot/src/core/content.dart';
11+
import 'package:test/test.dart';
12+
13+
void main() {
14+
group('Content should', () {
15+
group('be able to be instantiated using fromInteractionInput() with', () {
16+
test('null', () async {
17+
final contentSerdes = ContentSerdes();
18+
final content = Content.fromInteractionInput(
19+
null,
20+
'application/json',
21+
contentSerdes,
22+
null,
23+
);
24+
25+
expect(await content.body.isEmpty, isTrue);
26+
});
27+
28+
test('a DataSchemaValueInput', () async {
29+
final contentSerdes = ContentSerdes();
30+
const inputValue = 'foo';
31+
final input =
32+
DataSchemaValueInput(DataSchemaValue.fromString(inputValue));
33+
34+
final content = Content.fromInteractionInput(
35+
input,
36+
'application/json',
37+
contentSerdes,
38+
null,
39+
);
40+
41+
expect(await content.toByteList(), [34, 102, 111, 111, 34]);
42+
});
43+
44+
test('a StreamInput', () async {
45+
final contentSerdes = ContentSerdes();
46+
const inputValue = '"foo"';
47+
final byteList = [utf8.encode(inputValue)];
48+
final input = StreamInput(Stream.fromIterable(byteList));
49+
50+
final content = Content.fromInteractionInput(
51+
input,
52+
'application/json',
53+
contentSerdes,
54+
null,
55+
);
56+
57+
expect(await content.toByteList(), [34, 102, 111, 111, 34]);
58+
});
59+
});
60+
});
61+
}

0 commit comments

Comments
 (0)