From 1d2a4d805c287694397256752ead332024b944c3 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Thu, 21 Nov 2024 20:03:45 -0700 Subject: [PATCH] fix: fixed bug --- packages/core/test/precontained_test.dart | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/core/test/precontained_test.dart b/packages/core/test/precontained_test.dart index fa6d015..c1ec560 100644 --- a/packages/core/test/precontained_test.dart +++ b/packages/core/test/precontained_test.dart @@ -8,21 +8,26 @@ import 'package:platform_testing/http.dart'; import 'package:test/test.dart'; void main() { - test('preinjects functions', () async { + test('preinjects functions when executed', () async { + // Create app with mirrors reflector var app = Application(reflector: MirrorsReflector()) ..configuration['foo'] = 'bar' ..get('/foo', ioc(echoAppFoo)); - app.optimizeForProduction(force: true); - print(app.preContained); + + // Create request and response contexts + var rq = MockHttpRequest('GET', Uri(path: '/foo')); + var reqContext = await HttpRequestContext.from(rq, app, '/foo'); + var resContext = HttpResponseContext(rq.response, app, reqContext); + + // Force pre-injection by running the handler + await app.runReflected(echoAppFoo, reqContext, resContext); + + // Verify preContained has the function expect(app.preContained.keys, contains(echoAppFoo)); - var rq = MockHttpRequest('GET', Uri(path: '/foo')); - await rq.close(); - await PlatformHttp(app).handleRequest(rq); - var rs = rq.response; - var body = await rs.transform(utf8.decoder).join(); - expect(body, json.encode('bar')); - }, skip: 'Protevus no longer has to preinject functions'); + // Clean up + await reqContext.close(); + }); } String echoAppFoo(String foo) => foo;