11import { IncomingMessage , ServerResponse } from 'node:http' ;
22import { assert } from 'chai' ;
33import sinon from 'sinon' ;
4+ import { expectType } from 'tsd' ;
45import { ReceiverMultipleAckError } from '../../../src/errors' ;
56import * as HTTPModuleFunctions from '../../../src/receivers/HTTPModuleFunctions' ;
67import { HTTPResponseAck } from '../../../src/receivers/HTTPResponseAck' ;
8+ import type { ResponseAck } from '../../../src/types' ;
79import { createFakeLogger } from '../helpers' ;
810
911describe ( 'HTTPResponseAck' , async ( ) => {
10- it ( 'should work' , async ( ) => {
12+ it ( 'should implement ResponseAck and work' , async ( ) => {
1113 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
1214 const httpResponse : ServerResponse = sinon . createStubInstance ( ServerResponse ) as unknown as ServerResponse ;
13- const ack = new HTTPResponseAck ( {
15+ const responseAck = new HTTPResponseAck ( {
1416 logger : createFakeLogger ( ) ,
1517 processBeforeResponse : false ,
1618 httpRequest,
1719 httpResponse,
1820 } ) ;
19- assert . isDefined ( ack ) ;
20- assert . isDefined ( ack . bind ( ) ) ;
21- ack . ack ( ) ; // no exception
21+ assert . isDefined ( responseAck ) ;
22+ assert . isDefined ( responseAck . bind ( ) ) ;
23+ expectType < ResponseAck > ( responseAck ) ;
24+ responseAck . ack ( ) ; // no exception
2225 } ) ;
2326 it ( 'should trigger unhandledRequestHandler if unacknowledged' , ( done ) => {
2427 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
@@ -58,14 +61,14 @@ describe('HTTPResponseAck', async () => {
5861 it ( 'should throw an error if a bound Ack invocation was already acknowledged' , async ( ) => {
5962 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
6063 const httpResponse : ServerResponse = sinon . createStubInstance ( ServerResponse ) as unknown as ServerResponse ;
61- const ack = new HTTPResponseAck ( {
64+ const responseAck = new HTTPResponseAck ( {
6265 logger : createFakeLogger ( ) ,
6366 processBeforeResponse : false ,
6467 httpRequest,
6568 httpResponse,
6669 } ) ;
67- const bound = ack . bind ( ) ;
68- ack . ack ( ) ;
70+ const bound = responseAck . bind ( ) ;
71+ responseAck . ack ( ) ;
6972 try {
7073 await bound ( ) ;
7174 assert . fail ( 'No exception raised' ) ;
@@ -76,31 +79,31 @@ describe('HTTPResponseAck', async () => {
7679 it ( 'should store response body if processBeforeResponse=true' , async ( ) => {
7780 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
7881 const httpResponse : ServerResponse = sinon . createStubInstance ( ServerResponse ) as unknown as ServerResponse ;
79- const ack = new HTTPResponseAck ( {
82+ const responseAck = new HTTPResponseAck ( {
8083 logger : createFakeLogger ( ) ,
8184 processBeforeResponse : true ,
8285 httpRequest,
8386 httpResponse,
8487 } ) ;
85- const bound = ack . bind ( ) ;
88+ const bound = responseAck . bind ( ) ;
8689 const body = { some : 'thing' } ;
8790 await bound ( body ) ;
88- assert . equal ( ack . storedResponse , body , 'Body passed to bound handler not stored in Ack instance.' ) ;
91+ assert . equal ( responseAck . storedResponse , body , 'Body passed to bound handler not stored in Ack instance.' ) ;
8992 } ) ;
9093 it ( 'should store an empty string if response body is falsy and processBeforeResponse=true' , async ( ) => {
9194 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
9295 const httpResponse : ServerResponse = sinon . createStubInstance ( ServerResponse ) as unknown as ServerResponse ;
93- const ack = new HTTPResponseAck ( {
96+ const responseAck = new HTTPResponseAck ( {
9497 logger : createFakeLogger ( ) ,
9598 processBeforeResponse : true ,
9699 httpRequest,
97100 httpResponse,
98101 } ) ;
99- const bound = ack . bind ( ) ;
102+ const bound = responseAck . bind ( ) ;
100103 const body = false ;
101104 await bound ( body ) ;
102105 assert . equal (
103- ack . storedResponse ,
106+ responseAck . storedResponse ,
104107 '' ,
105108 'Falsy body passed to bound handler not stored as empty string in Ack instance.' ,
106109 ) ;
@@ -109,13 +112,13 @@ describe('HTTPResponseAck', async () => {
109112 const stub = sinon . stub ( HTTPModuleFunctions , 'buildContentResponse' ) ;
110113 const httpRequest = sinon . createStubInstance ( IncomingMessage ) as IncomingMessage ;
111114 const httpResponse : ServerResponse = sinon . createStubInstance ( ServerResponse ) as unknown as ServerResponse ;
112- const ack = new HTTPResponseAck ( {
115+ const responseAck = new HTTPResponseAck ( {
113116 logger : createFakeLogger ( ) ,
114117 processBeforeResponse : false ,
115118 httpRequest,
116119 httpResponse,
117120 } ) ;
118- const bound = ack . bind ( ) ;
121+ const bound = responseAck . bind ( ) ;
119122 const body = { some : 'thing' } ;
120123 await bound ( body ) ;
121124 assert (
0 commit comments