@@ -281,21 +281,17 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
281
281
writer .openBlock ("it($S, async () => {" , "});\n " , testName , () -> {
282
282
Symbol serviceSymbol = serverSymbolProvider .toSymbol (service );
283
283
Symbol handlerSymbol = serviceSymbol .expectProperty ("handler" , Symbol .class );
284
- Symbol inputType = operationSymbol .expectProperty ("inputType" , Symbol .class );
285
- Symbol outputType = operationSymbol .expectProperty ("outputType" , Symbol .class );
286
284
287
285
// Create a mock function to set in place of the server operation function so we can capture
288
286
// input and other information.
289
287
writer .write ("let testFunction = jest.fn();" );
290
- writer .write ("testFunction.mockReturnValue({} );" );
288
+ writer .write ("testFunction.mockReturnValue(Promise.resolve({}) );" );
291
289
292
290
// We use a partial here so that we don't have to define the entire service, but still get the advantages
293
291
// the type checker, including excess property checking. Later on we'll use `as` to cast this to the
294
292
// full service so that we can actually use it.
295
293
writer .openBlock ("const testService: Partial<$T> = {" , "};" , serviceSymbol , () -> {
296
- writer .addImport ("Operation" , "__Operation" , "@aws-smithy/server-common" );
297
- writer .write ("$L: testFunction as __Operation<$T, $T>," ,
298
- operationSymbol .getName (), inputType , outputType );
294
+ writer .write ("$L: testFunction as $T," , operationSymbol .getName (), operationSymbol );
299
295
});
300
296
301
297
String getHandlerName = "get" + handlerSymbol .getName ();
@@ -322,7 +318,6 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
322
318
323
319
// Capture the input. We need to cast this to any so we can index into it.
324
320
writer .write ("let r: any = testFunction.mock.calls[0][0];" ).write ("" );
325
-
326
321
writeRequestParamAssertions (operation , testCase );
327
322
});
328
323
}
@@ -492,16 +487,16 @@ public void generateServerResponseTest(OperationShape operation, HttpResponseTes
492
487
writer .openBlock ("it($S, async () => {" , "});\n " , testName , () -> {
493
488
Symbol outputType = operationSymbol .expectProperty ("outputType" , Symbol .class );
494
489
writer .openBlock ("class TestService implements Partial<$T> {" , "}" , serviceSymbol , () -> {
495
- writer .openBlock ("$L(input: any, request: HttpRequest): $T {" , "}" ,
490
+ writer .openBlock ("$L(input: any, request: HttpRequest): Promise<$T> {" , "}" ,
496
491
operationSymbol .getName (), outputType , () -> {
497
492
Optional <ShapeId > outputOptional = operation .getOutput ();
498
493
if (outputOptional .isPresent ()) {
499
494
StructureShape outputShape = model .expectShape (outputOptional .get (), StructureShape .class );
500
495
writer .writeInline ("let response = " );
501
496
testCase .getParams ().accept (new CommandInputNodeVisitor (outputShape , true ));
502
- writer .write ("return { ...response, '$$metadata': {} };" );
497
+ writer .write ("return Promise.resolve( { ...response, '$$metadata': {} }) ;" );
503
498
} else {
504
- writer .write ("return { '$$metadata': {} };" );
499
+ writer .write ("return Promise.resolve( { '$$metadata': {} }) ;" );
505
500
}
506
501
});
507
502
});
@@ -547,7 +542,7 @@ private void generateServerErrorResponseTest(
547
542
// but using the partial in the meantime will give us proper type checking on the
548
543
// operation we want.
549
544
writer .openBlock ("class TestService implements Partial<$T> {" , "}" , serviceSymbol , () -> {
550
- writer .openBlock ("$L(input: any, request: HttpRequest): $T {" , "}" ,
545
+ writer .openBlock ("$L(input: any, request: HttpRequest): Promise<$T> {" , "}" ,
551
546
operationSymbol .getName (), outputType , () -> {
552
547
// Write out an object according to what's defined in the test case.
553
548
writer .writeInline ("const response = " );
@@ -608,7 +603,9 @@ private void writeServerResponseTest(OperationShape operation, HttpResponseTestC
608
603
writer .openBlock ("const serFn: (op: $1T) => __OperationSerializer<$2T, $1T, __SmithyException> = (op) =>"
609
604
+ " { return new TestSerializer(); };" , serviceOperationsSymbol , serviceSymbol );
610
605
611
- writer .write ("const handler = new $T(service, testMux, serFn);" , handlerSymbol );
606
+ writer .addImport ("serializeFrameworkException" , null ,
607
+ "./protocols/" + ProtocolGenerator .getSanitizedName (protocolGenerator .getName ()));
608
+ writer .write ("const handler = new $T(service, testMux, serFn, serializeFrameworkException);" , handlerSymbol );
612
609
writer .write ("let r = await handler.handle(request)" ).write ("" );
613
610
writeHttpResponseAssertions (testCase );
614
611
}
0 commit comments