From 16fc8c3436c87f77e5395046276f92303b8c014b Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sat, 29 May 2021 07:44:06 +0800 Subject: [PATCH] Fixed framework test cases --- CHANGELOG.md | 2 +- .../lib/src/core/response_context.dart | 6 +++--- packages/framework/lib/src/core/routable.dart | 2 +- packages/framework/pubspec.yaml | 3 +-- packages/framework/test/primitives_test.dart | 17 ++++++----------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8194a521..f82535f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ * Migrated angel_container to 3.0.0 (55/55 tests passed) * Added merge_map and migrated to 2.0.0 (6/6 tests passed) * Added mock_request and migrated to 2.0.0 (0/0 tests) -* Migrated angel_framework to 4.0.0 (146/150 tests passed) +* Migrated angel_framework to 4.0.0 (148/150 tests passed) * Migrated angel_auth to 4.0.0 (23/30 tests passed) * Migrated angel_configuration to 4.0.0 (6/8 testspassed) * Migrated angel_validate to 4.0.0 (6/7 tests passed) diff --git a/packages/framework/lib/src/core/response_context.dart b/packages/framework/lib/src/core/response_context.dart index d67e71e2..1c7ff9a3 100644 --- a/packages/framework/lib/src/core/response_context.dart +++ b/packages/framework/lib/src/core/response_context.dart @@ -74,7 +74,7 @@ abstract class ResponseContext /// ```dart /// app.injectSerializer(JSON.encode); /// ``` - FutureOr Function(dynamic)? serializer = c.json.encode; + FutureOr Function(dynamic) serializer = c.json.encode; /// This response's status code. int get statusCode => _statusCode; @@ -182,7 +182,7 @@ abstract class ResponseContext {String callbackName = "callback", MediaType? contentType}) { if (!isOpen) throw closed(); this.contentType = contentType ?? MediaType('application', 'javascript'); - write("$callbackName(${serializer!(value)})"); + write("$callbackName(${serializer(value)})"); return close(); } @@ -308,7 +308,7 @@ abstract class ResponseContext Future serialize(value, {MediaType? contentType}) async { if (!isOpen) throw closed(); this.contentType = contentType ?? MediaType('application', 'json'); - var text = await serializer!(value); + var text = await serializer(value); if (text.isEmpty) return true; write(text); await close(); diff --git a/packages/framework/lib/src/core/routable.dart b/packages/framework/lib/src/core/routable.dart index 04a4591e..d4e9f72a 100644 --- a/packages/framework/lib/src/core/routable.dart +++ b/packages/framework/lib/src/core/routable.dart @@ -31,7 +31,7 @@ RequestHandler chain(Iterable handlers) { runPipeline = () => Future.sync(() => handler(req, res)); } else { var current = runPipeline; - runPipeline = () => current().then((result) => res.isOpen + runPipeline = () => current().then((result) => !res.isOpen ? Future.value(result) : req.app!.executeHandler(handler, req, res)); } diff --git a/packages/framework/pubspec.yaml b/packages/framework/pubspec.yaml index 7b4ad49b..d20baf67 100644 --- a/packages/framework/pubspec.yaml +++ b/packages/framework/pubspec.yaml @@ -9,8 +9,7 @@ dependencies: angel3_container: ^3.0.0 angel3_http_exception: ^3.0.0 angel3_model: ^3.0.0 - angel3_route: #^5.0.0 - path: ../route + angel3_route: ^5.0.0 angel3_combinator: ^2.0.0 angel3_merge_map: ^2.0.0 angel3_mock_request: ^2.0.0 diff --git a/packages/framework/test/primitives_test.dart b/packages/framework/test/primitives_test.dart index d3a35c1f..ddac35be 100644 --- a/packages/framework/test/primitives_test.dart +++ b/packages/framework/test/primitives_test.dart @@ -63,16 +63,11 @@ void main() { }); test('unparsed primitive throws error', () async { - try { - var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32')); - await rq.close(); - var req = await http.createRequestContext(rq, rq.response); - var res = await http.createResponseContext(rq, rq.response, req); - await app.runContained((num unparsed) => unparsed, req, res); - throw StateError( - 'ArgumentError should be thrown if a parameter cannot be resolved.'); - } on ArgumentError { - // Success - } + var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32')); + await rq.close(); + var req = await http.createRequestContext(rq, rq.response); + var res = await http.createResponseContext(rq, rq.response, req); + expect(() => app.runContained((num unparsed) => unparsed, req, res), + throwsA(isA())); }); }