@@ -34,7 +34,8 @@ const sendRequest = (
34
34
req . end ( ) ;
35
35
} ;
36
36
37
- const postData = JSON . stringify ( { action : 'test' , foo : 'bar' } ) ;
37
+ const data = { action : 'test' , foo : 'bar' } ;
38
+ const postData = JSON . stringify ( data ) ;
38
39
describe ( 'hukk' , ( ) => {
39
40
beforeAll ( done => {
40
41
hukk . listen ( testPort , done ) ;
@@ -51,14 +52,30 @@ describe('hukk', () => {
51
52
52
53
it ( 'hook response what it received' , done => {
53
54
const handle = ( body : any ) => {
54
- return body
55
- }
56
- hukk . register ( { endpoint : '/another-webhook' , handle} )
57
- sendRequest ( '/another-webhook' , postData , ( err , data ) => {
58
- expect ( data ) . toEqual ( postData )
59
- done ( )
60
- } )
61
- } )
55
+ return body ;
56
+ } ;
57
+ hukk . register ( { endpoint : '/another-webhook' , handle} ) ;
58
+ sendRequest ( '/another-webhook' , postData , ( err , responseData ) => {
59
+ const compareTo = JSON . parse ( JSON . stringify ( { body : data } ) )
60
+ const compareFrom = JSON . parse ( responseData )
61
+ expect ( compareFrom ) . toEqual ( compareTo ) ;
62
+ done ( ) ;
63
+ } ) ;
64
+ } ) ;
65
+
66
+ it ( 'hook response with plain text' , done => {
67
+ const text = 'plain text string'
68
+ const handle = ( body : any ) => {
69
+ return body ;
70
+ } ;
71
+ hukk . register ( { endpoint : '/another-webhook' , handle} ) ;
72
+ sendRequest ( '/another-webhook' , text , ( err , responseData ) => {
73
+ const compareTo = JSON . parse ( JSON . stringify ( { body : text } ) )
74
+ const compareFrom = JSON . parse ( responseData )
75
+ expect ( compareFrom ) . toEqual ( compareTo ) ;
76
+ done ( ) ;
77
+ } ) ;
78
+ } ) ;
62
79
63
80
afterAll ( done => {
64
81
hukk . close ( done ) ;
0 commit comments