@@ -2,16 +2,20 @@ import { Test, TestingModule } from '@nestjs/testing';
22import { CronJobService } from './cron-job.service' ;
33import { HttpStatus , Logger } from '@nestjs/common' ;
44import { CronJobRepository } from './cron-job.repository' ;
5- import { WebhookService } from '../webhook/webhook.service' ;
65import { CronJobEntity } from './cron-job.entity' ;
76import { CronJobType } from '../../common/enums/cron-job' ;
87import { ErrorCronJob } from '../../common/constants/errors' ;
98import { ControlledError } from '../../common/errors/controlled' ;
9+ import { WebhookOutgoingService } from '../webhook/webhook-outgoing.service' ;
10+ import { WebhookIncomingService } from '../webhook/webhook-incoming.service' ;
11+ import { EscrowCompletionTrackingService } from '../escrow-completion-tracking/escrow-completion-tracking.service' ;
1012
1113describe ( 'CronJobService' , ( ) => {
1214 let service : CronJobService ;
1315 let cronJobRepository : jest . Mocked < CronJobRepository > ;
14- let webhookService : jest . Mocked < WebhookService > ;
16+ let webhookIncomingService : jest . Mocked < WebhookIncomingService > ;
17+ let webhookOutgoingService : jest . Mocked < WebhookOutgoingService > ;
18+ let escrowCompletionTrackingService : jest . Mocked < EscrowCompletionTrackingService > ;
1519
1620 beforeEach ( async ( ) => {
1721 const module : TestingModule = await Test . createTestingModule ( {
@@ -26,12 +30,22 @@ describe('CronJobService', () => {
2630 } ,
2731 } ,
2832 {
29- provide : WebhookService ,
33+ provide : WebhookIncomingService ,
3034 useValue : {
3135 processPendingIncomingWebhooks : jest . fn ( ) ,
36+ } ,
37+ } ,
38+ {
39+ provide : WebhookOutgoingService ,
40+ useValue : {
41+ processPendingOutgoingWebhooks : jest . fn ( ) ,
42+ } ,
43+ } ,
44+ {
45+ provide : EscrowCompletionTrackingService ,
46+ useValue : {
3247 processPendingEscrowCompletion : jest . fn ( ) ,
3348 processPaidEscrowCompletion : jest . fn ( ) ,
34- processPendingOutgoingWebhooks : jest . fn ( ) ,
3549 } ,
3650 } ,
3751 {
@@ -46,7 +60,11 @@ describe('CronJobService', () => {
4660
4761 service = module . get < CronJobService > ( CronJobService ) ;
4862 cronJobRepository = module . get ( CronJobRepository ) ;
49- webhookService = module . get ( WebhookService ) ;
63+ webhookIncomingService = module . get ( WebhookIncomingService ) ;
64+ webhookOutgoingService = module . get ( WebhookOutgoingService ) ;
65+ escrowCompletionTrackingService = module . get (
66+ EscrowCompletionTrackingService ,
67+ ) ;
5068 } ) ;
5169
5270 describe ( 'startCronJob' , ( ) => {
@@ -164,7 +182,7 @@ describe('CronJobService', () => {
164182 await service . processPendingIncomingWebhooks ( ) ;
165183
166184 expect (
167- webhookService . processPendingIncomingWebhooks ,
185+ webhookIncomingService . processPendingIncomingWebhooks ,
168186 ) . not . toHaveBeenCalled ( ) ;
169187 } ) ;
170188
@@ -179,7 +197,9 @@ describe('CronJobService', () => {
179197
180198 await service . processPendingIncomingWebhooks ( ) ;
181199
182- expect ( webhookService . processPendingIncomingWebhooks ) . toHaveBeenCalled ( ) ;
200+ expect (
201+ webhookIncomingService . processPendingIncomingWebhooks ,
202+ ) . toHaveBeenCalled ( ) ;
183203 expect ( service . startCronJob ) . toHaveBeenCalled ( ) ;
184204 expect ( service . completeCronJob ) . toHaveBeenCalled ( ) ;
185205 } ) ;
@@ -193,7 +213,7 @@ describe('CronJobService', () => {
193213 . spyOn ( service , 'completeCronJob' )
194214 . mockResolvedValue ( new CronJobEntity ( ) ) ;
195215
196- webhookService . processPendingIncomingWebhooks . mockRejectedValue (
216+ webhookIncomingService . processPendingIncomingWebhooks . mockRejectedValue (
197217 new Error ( 'Processing error' ) ,
198218 ) ;
199219
@@ -210,7 +230,7 @@ describe('CronJobService', () => {
210230 await service . processPendingEscrowCompletion ( ) ;
211231
212232 expect (
213- webhookService . processPendingEscrowCompletion ,
233+ escrowCompletionTrackingService . processPendingEscrowCompletion ,
214234 ) . not . toHaveBeenCalled ( ) ;
215235 } ) ;
216236
@@ -225,7 +245,9 @@ describe('CronJobService', () => {
225245
226246 await service . processPendingEscrowCompletion ( ) ;
227247
228- expect ( webhookService . processPendingEscrowCompletion ) . toHaveBeenCalled ( ) ;
248+ expect (
249+ escrowCompletionTrackingService . processPendingEscrowCompletion ,
250+ ) . toHaveBeenCalled ( ) ;
229251 expect ( service . startCronJob ) . toHaveBeenCalled ( ) ;
230252 expect ( service . completeCronJob ) . toHaveBeenCalled ( ) ;
231253 } ) ;
@@ -239,7 +261,7 @@ describe('CronJobService', () => {
239261 . spyOn ( service , 'completeCronJob' )
240262 . mockResolvedValue ( new CronJobEntity ( ) ) ;
241263
242- webhookService . processPendingEscrowCompletion . mockRejectedValue (
264+ escrowCompletionTrackingService . processPendingEscrowCompletion . mockRejectedValue (
243265 new Error ( 'Processing error' ) ,
244266 ) ;
245267
@@ -255,7 +277,9 @@ describe('CronJobService', () => {
255277
256278 await service . processPaidEscrowCompletion ( ) ;
257279
258- expect ( webhookService . processPaidEscrowCompletion ) . not . toHaveBeenCalled ( ) ;
280+ expect (
281+ escrowCompletionTrackingService . processPaidEscrowCompletion ,
282+ ) . not . toHaveBeenCalled ( ) ;
259283 } ) ;
260284
261285 it ( 'should process paid escrow completion and complete the cron job' , async ( ) => {
@@ -269,7 +293,9 @@ describe('CronJobService', () => {
269293
270294 await service . processPaidEscrowCompletion ( ) ;
271295
272- expect ( webhookService . processPaidEscrowCompletion ) . toHaveBeenCalled ( ) ;
296+ expect (
297+ escrowCompletionTrackingService . processPaidEscrowCompletion ,
298+ ) . toHaveBeenCalled ( ) ;
273299 expect ( service . startCronJob ) . toHaveBeenCalled ( ) ;
274300 expect ( service . completeCronJob ) . toHaveBeenCalled ( ) ;
275301 } ) ;
@@ -283,7 +309,7 @@ describe('CronJobService', () => {
283309 . spyOn ( service , 'completeCronJob' )
284310 . mockResolvedValue ( new CronJobEntity ( ) ) ;
285311
286- webhookService . processPaidEscrowCompletion . mockRejectedValue (
312+ escrowCompletionTrackingService . processPaidEscrowCompletion . mockRejectedValue (
287313 new Error ( 'Processing error' ) ,
288314 ) ;
289315
@@ -300,7 +326,7 @@ describe('CronJobService', () => {
300326 await service . processPendingOutgoingWebhooks ( ) ;
301327
302328 expect (
303- webhookService . processPendingOutgoingWebhooks ,
329+ webhookOutgoingService . processPendingOutgoingWebhooks ,
304330 ) . not . toHaveBeenCalled ( ) ;
305331 } ) ;
306332
@@ -315,7 +341,9 @@ describe('CronJobService', () => {
315341
316342 await service . processPendingOutgoingWebhooks ( ) ;
317343
318- expect ( webhookService . processPendingOutgoingWebhooks ) . toHaveBeenCalled ( ) ;
344+ expect (
345+ webhookOutgoingService . processPendingOutgoingWebhooks ,
346+ ) . toHaveBeenCalled ( ) ;
319347 expect ( service . startCronJob ) . toHaveBeenCalled ( ) ;
320348 expect ( service . completeCronJob ) . toHaveBeenCalled ( ) ;
321349 } ) ;
@@ -329,7 +357,7 @@ describe('CronJobService', () => {
329357 . spyOn ( service , 'completeCronJob' )
330358 . mockResolvedValue ( new CronJobEntity ( ) ) ;
331359
332- webhookService . processPendingOutgoingWebhooks . mockRejectedValue (
360+ webhookOutgoingService . processPendingOutgoingWebhooks . mockRejectedValue (
333361 new Error ( 'Processing error' ) ,
334362 ) ;
335363
0 commit comments