@@ -54,8 +54,14 @@ import { WebhooksService } from './webhooks.service';
54
54
const webhookSecret = process . env . STORYBLOK_WEBHOOK_SECRET ;
55
55
56
56
const getWebhookSignature = ( body ) => {
57
- return createHmac ( 'sha1' , webhookSecret ) . update ( JSON . stringify ( body ) ) . digest ( 'hex' ) ;
57
+ return createHmac ( 'sha1' , webhookSecret ) . update ( "" + body ) . digest ( 'hex' ) ;
58
58
} ;
59
+ const createRequestObject = ( body ) => {
60
+ return {
61
+ rawBody : "" + body ,
62
+ setEncoding : ( ) => { } ,
63
+ encoding : "utf8"
64
+ } }
59
65
60
66
// Difficult to mock classes as well as node modules.
61
67
// This seemed the best approach
@@ -228,7 +234,7 @@ describe('WebhooksService', () => {
228
234
text : '' ,
229
235
} ;
230
236
231
- return expect ( service . updateStory ( body , getWebhookSignature ( body ) ) ) . rejects . toThrow (
237
+ return expect ( service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ) . rejects . toThrow (
232
238
'STORYBLOK STORY NOT FOUND' ,
233
239
) ;
234
240
} ) ;
@@ -241,6 +247,7 @@ describe('WebhooksService', () => {
241
247
} ;
242
248
243
249
const deletedStory = ( await service . updateStory (
250
+ createRequestObject ( body ) ,
244
251
body ,
245
252
getWebhookSignature ( body ) ,
246
253
) ) as SessionEntity ;
@@ -256,6 +263,7 @@ describe('WebhooksService', () => {
256
263
} ;
257
264
258
265
const unpublished = ( await service . updateStory (
266
+ createRequestObject ( body ) ,
259
267
body ,
260
268
getWebhookSignature ( body ) ,
261
269
) ) as SessionEntity ;
@@ -306,7 +314,7 @@ describe('WebhooksService', () => {
306
314
text : '' ,
307
315
} ;
308
316
309
- const session = ( await service . updateStory ( body , getWebhookSignature ( body ) ) ) as SessionEntity ;
317
+ const session = ( await service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ) as SessionEntity ;
310
318
311
319
expect ( courseFindOneSpy ) . toHaveBeenCalledWith ( {
312
320
storyblokUuid : 'anotherCourseUuId' ,
@@ -349,7 +357,7 @@ describe('WebhooksService', () => {
349
357
text : '' ,
350
358
} ;
351
359
352
- const session = ( await service . updateStory ( body , getWebhookSignature ( body ) ) ) as SessionEntity ;
360
+ const session = ( await service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ) as SessionEntity ;
353
361
354
362
expect ( session ) . toEqual ( mockSession ) ;
355
363
expect ( courseFindOneSpy ) . toHaveBeenCalledWith ( {
@@ -408,7 +416,7 @@ describe('WebhooksService', () => {
408
416
text : '' ,
409
417
} ;
410
418
411
- const session = ( await service . updateStory ( body , getWebhookSignature ( body ) ) ) as SessionEntity ;
419
+ const session = ( await service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ) as SessionEntity ;
412
420
413
421
expect ( session ) . toEqual ( mockSession ) ;
414
422
expect ( sessionSaveRepoSpy ) . toHaveBeenCalledWith ( {
@@ -442,7 +450,7 @@ describe('WebhooksService', () => {
442
450
text : '' ,
443
451
} ;
444
452
445
- const course = ( await service . updateStory ( body , getWebhookSignature ( body ) ) ) as CourseEntity ;
453
+ const course = ( await service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ) as CourseEntity ;
446
454
447
455
expect ( course ) . toEqual ( mockCourse ) ;
448
456
expect ( courseFindOneRepoSpy ) . toHaveBeenCalledWith ( {
0 commit comments