-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for JSON schema validation of values
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2022 The NAMIB Project Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import 'package:dart_wot/src/core/content.dart'; | ||
import 'package:dart_wot/src/core/content_serdes.dart'; | ||
import 'package:dart_wot/src/definitions/data_schema.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
Content _getTestContent() { | ||
return Content("application/json", Stream<List<int>>.value('42'.codeUnits)); | ||
} | ||
|
||
void main() { | ||
group('Content Serdes Tests', () { | ||
setUp(() { | ||
// Additional setup goes here. | ||
}); | ||
}); | ||
|
||
test('Content Validation', () async { | ||
final contentSerdes = ContentSerdes(); | ||
|
||
final testContent1 = _getTestContent(); | ||
final successfulSchema = | ||
DataSchema.fromJson(<String, dynamic>{"type": "number"}); | ||
|
||
expect( | ||
await contentSerdes.contentToValue(testContent1, successfulSchema), 42); | ||
|
||
final testContent2 = _getTestContent(); | ||
final failingSchema = | ||
DataSchema.fromJson(<String, dynamic>{"type": "string"}); | ||
|
||
expect(contentSerdes.contentToValue(testContent2, failingSchema), | ||
throwsA(TypeMatcher<ContentSerdesException>())); | ||
|
||
expect( | ||
() => | ||
contentSerdes.valueToContent(42, failingSchema, "application/json"), | ||
throwsA(TypeMatcher<ContentSerdesException>())); | ||
}); | ||
} |