@@ -64,11 +64,7 @@ async fn test_forwarding_no_verification() {
64
64
. uri ( "/webhook/a" )
65
65
. method ( "POST" )
66
66
. header ( "content-type" , "application/json" )
67
- . body (
68
- serde_json:: to_vec ( & json ! ( { "payload" : { "a" : true } } ) )
69
- . unwrap ( )
70
- . into ( ) ,
71
- )
67
+ . body ( serde_json:: to_vec ( & json ! ( { "a" : true } ) ) . unwrap ( ) . into ( ) )
72
68
. unwrap ( ) ,
73
69
)
74
70
. await
@@ -112,11 +108,7 @@ async fn test_forwarding_multiple_receivers() {
112
108
. uri ( "/webhook/a" )
113
109
. method ( "POST" )
114
110
. header ( "content-type" , "application/json" )
115
- . body (
116
- serde_json:: to_vec ( & json ! ( { "payload" : { "a" : true } } ) )
117
- . unwrap ( )
118
- . into ( ) ,
119
- )
111
+ . body ( serde_json:: to_vec ( & json ! ( { "a" : true } ) ) . unwrap ( ) . into ( ) )
120
112
. unwrap ( ) ;
121
113
122
114
let response = ServiceExt :: < Request < Body > > :: ready ( & mut app)
@@ -134,11 +126,7 @@ async fn test_forwarding_multiple_receivers() {
134
126
. uri ( "/webhook/b" )
135
127
. method ( "POST" )
136
128
. header ( "content-type" , "application/json" )
137
- . body (
138
- serde_json:: to_vec ( & json ! ( { "payload" : { "b" : true } } ) )
139
- . unwrap ( )
140
- . into ( ) ,
141
- )
129
+ . body ( serde_json:: to_vec ( & json ! ( { "b" : true } ) ) . unwrap ( ) . into ( ) )
142
130
. unwrap ( ) ;
143
131
144
132
let response = ServiceExt :: < Request < Body > > :: ready ( & mut app)
@@ -163,15 +151,18 @@ async fn test_transformation_json() {
163
151
let ( tx, mut rx) = tokio:: sync:: mpsc:: unbounded_channel :: < TransformerJob > ( ) ;
164
152
let _handle = tokio:: spawn ( async move {
165
153
while let Some ( x) = rx. recv ( ) . await {
166
- let mut out = match x. input {
154
+ let mut input = match x. input {
167
155
TransformerInput :: JSON ( input) => input. as_object ( ) . unwrap ( ) . clone ( ) ,
168
156
_ => unreachable ! ( ) ,
169
157
} ;
170
- out[ "payload" ]
171
- . as_object_mut ( )
172
- . unwrap ( )
173
- . insert ( "__TRANSFORMED__" . into ( ) , json ! ( true ) ) ;
174
- x. callback_tx . send ( Ok ( TransformerOutput :: Object ( out) ) ) . ok ( ) ;
158
+ input. insert ( "__TRANSFORMED__" . into ( ) , json ! ( true ) ) ;
159
+ let out = json ! ( { "payload" : input } ) ;
160
+
161
+ x. callback_tx
162
+ . send ( Ok ( TransformerOutput :: Object (
163
+ out. as_object ( ) . unwrap ( ) . clone ( ) ,
164
+ ) ) )
165
+ . ok ( ) ;
175
166
}
176
167
} ) ;
177
168
@@ -184,7 +175,7 @@ async fn test_transformation_json() {
184
175
verifier : NoVerifier . into ( ) ,
185
176
output : Arc :: new ( Box :: new ( a_output) ) ,
186
177
transformation : Some (
187
- "handler = (x) => ({ payload: {__TRANSFORMED__: true, ...x.payload }})" . into ( ) ,
178
+ "handler = (x) => ({ payload: {__TRANSFORMED__: true, ...x }})" . into ( ) ,
188
179
) ,
189
180
} ,
190
181
) ,
@@ -207,11 +198,7 @@ async fn test_transformation_json() {
207
198
. uri ( "/webhook/transformed" )
208
199
. method ( "POST" )
209
200
. header ( "content-type" , "application/json" )
210
- . body (
211
- serde_json:: to_vec ( & json ! ( { "payload" : { "a" : true } } ) )
212
- . unwrap ( )
213
- . into ( ) ,
214
- )
201
+ . body ( serde_json:: to_vec ( & json ! ( { "a" : true } ) ) . unwrap ( ) . into ( ) )
215
202
. unwrap ( ) ;
216
203
217
204
let response = ServiceExt :: < Request < Body > > :: ready ( & mut app)
@@ -233,11 +220,7 @@ async fn test_transformation_json() {
233
220
. uri ( "/webhook/as-is" )
234
221
. method ( "POST" )
235
222
. header ( "content-type" , "application/json" )
236
- . body (
237
- serde_json:: to_vec ( & json ! ( { "payload" : { "b" : true } } ) )
238
- . unwrap ( )
239
- . into ( ) ,
240
- )
223
+ . body ( serde_json:: to_vec ( & json ! ( { "b" : true } ) ) . unwrap ( ) . into ( ) )
241
224
. unwrap ( ) ;
242
225
243
226
let response = ServiceExt :: < Request < Body > > :: ready ( & mut app)
@@ -371,7 +354,7 @@ async fn test_forwarding_svix_verification_match() {
371
354
372
355
let webhook = Arc :: new ( Webhook :: new ( "whsec_C2FVsBQIhrscChlQIMV+b5sSYspob7oD" ) . unwrap ( ) ) ;
373
356
374
- let payload = json ! ( { "payload" : { " a": true } } ) ;
357
+ let payload = json ! ( { "a" : true } ) ;
375
358
let payload_bytes = serde_json:: to_vec ( & payload) . unwrap ( ) ;
376
359
let timestamp = chrono:: Utc :: now ( ) . timestamp ( ) ;
377
360
let signature = webhook
0 commit comments