1
1
import { createMock } from '@golevelup/ts-jest' ;
2
2
import { Test , TestingModule } from '@nestjs/testing' ;
3
3
import { getRepositoryToken } from '@nestjs/typeorm' ;
4
- import { createHmac } from 'crypto' ;
5
4
import { SlackMessageClient } from 'src/api/slack/slack-api' ;
6
5
import { CoursePartnerService } from 'src/course-partner/course-partner.service' ;
7
6
import { CoursePartnerEntity } from 'src/entities/course-partner.entity' ;
@@ -47,21 +46,6 @@ import { ILike, Repository } from 'typeorm';
47
46
import { WebhookCreateEventLogDto } from './dto/webhook-create-event-log.dto' ;
48
47
import { WebhooksService } from './webhooks.service' ;
49
48
50
- const webhookSecret = process . env . STORYBLOK_WEBHOOK_SECRET ;
51
-
52
- const getWebhookSignature = ( body ) => {
53
- return createHmac ( 'sha1' , webhookSecret )
54
- . update ( '' + body )
55
- . digest ( 'hex' ) ;
56
- } ;
57
- const createRequestObject = ( body ) => {
58
- return {
59
- rawBody : '' + body ,
60
- setEncoding : ( ) => { } ,
61
- encoding : 'utf8' ,
62
- } ;
63
- } ;
64
-
65
49
// Difficult to mock classes as well as node modules.
66
50
// This seemed the best approach
67
51
jest . mock ( 'storyblok-js-client' , ( ) => {
@@ -202,9 +186,7 @@ describe('WebhooksService', () => {
202
186
text : '' ,
203
187
} ;
204
188
205
- return expect (
206
- service . updateStory ( createRequestObject ( body ) , body , getWebhookSignature ( body ) ) ,
207
- ) . rejects . toThrow ( 'STORYBLOK STORY NOT FOUND' ) ;
189
+ return expect ( service . updateStory ( body ) ) . rejects . toThrow ( 'STORYBLOK STORY NOT FOUND' ) ;
208
190
} ) ;
209
191
210
192
it ( 'when action is deleted, story should be set as deleted in database' , async ( ) => {
@@ -214,11 +196,7 @@ describe('WebhooksService', () => {
214
196
text : '' ,
215
197
} ;
216
198
217
- const deletedStory = ( await service . updateStory (
218
- createRequestObject ( body ) ,
219
- body ,
220
- getWebhookSignature ( body ) ,
221
- ) ) as SessionEntity ;
199
+ const deletedStory = ( await service . updateStory ( body ) ) as SessionEntity ;
222
200
223
201
expect ( deletedStory . status ) . toBe ( STORYBLOK_STORY_STATUS_ENUM . DELETED ) ;
224
202
} ) ;
@@ -230,11 +208,7 @@ describe('WebhooksService', () => {
230
208
text : '' ,
231
209
} ;
232
210
233
- const unpublished = ( await service . updateStory (
234
- createRequestObject ( body ) ,
235
- body ,
236
- getWebhookSignature ( body ) ,
237
- ) ) as SessionEntity ;
211
+ const unpublished = ( await service . updateStory ( body ) ) as SessionEntity ;
238
212
239
213
expect ( unpublished . status ) . toBe ( STORYBLOK_STORY_STATUS_ENUM . UNPUBLISHED ) ;
240
214
} ) ;
@@ -282,11 +256,7 @@ describe('WebhooksService', () => {
282
256
text : '' ,
283
257
} ;
284
258
285
- const session = ( await service . updateStory (
286
- createRequestObject ( body ) ,
287
- body ,
288
- getWebhookSignature ( body ) ,
289
- ) ) as SessionEntity ;
259
+ const session = ( await service . updateStory ( body ) ) as SessionEntity ;
290
260
291
261
expect ( courseFindOneSpy ) . toHaveBeenCalledWith ( {
292
262
storyblokUuid : 'anotherCourseUuId' ,
@@ -329,11 +299,7 @@ describe('WebhooksService', () => {
329
299
text : '' ,
330
300
} ;
331
301
332
- const session = ( await service . updateStory (
333
- createRequestObject ( body ) ,
334
- body ,
335
- getWebhookSignature ( body ) ,
336
- ) ) as SessionEntity ;
302
+ const session = ( await service . updateStory ( body ) ) as SessionEntity ;
337
303
338
304
expect ( session ) . toEqual ( mockSession ) ;
339
305
expect ( courseFindOneSpy ) . toHaveBeenCalledWith ( {
@@ -392,11 +358,7 @@ describe('WebhooksService', () => {
392
358
text : '' ,
393
359
} ;
394
360
395
- const session = ( await service . updateStory (
396
- createRequestObject ( body ) ,
397
- body ,
398
- getWebhookSignature ( body ) ,
399
- ) ) as SessionEntity ;
361
+ const session = ( await service . updateStory ( body ) ) as SessionEntity ;
400
362
401
363
expect ( session ) . toEqual ( mockSession ) ;
402
364
expect ( sessionSaveRepoSpy ) . toHaveBeenCalledWith ( {
@@ -430,11 +392,7 @@ describe('WebhooksService', () => {
430
392
text : '' ,
431
393
} ;
432
394
433
- const course = ( await service . updateStory (
434
- createRequestObject ( body ) ,
435
- body ,
436
- getWebhookSignature ( body ) ,
437
- ) ) as CourseEntity ;
395
+ const course = ( await service . updateStory ( body ) ) as CourseEntity ;
438
396
439
397
expect ( course ) . toEqual ( mockCourse ) ;
440
398
expect ( courseFindOneRepoSpy ) . toHaveBeenCalledWith ( {
0 commit comments