@@ -3,14 +3,30 @@ import { createMockService } from "~tests/mocks/service.js";
3
3
import { createMockScheduleModel } from "~tests/mocks/scheduleModel.js" ;
4
4
import { createMockCms } from "~tests/mocks/cms.js" ;
5
5
import { createMockFetcher } from "~tests/mocks/fetcher.js" ;
6
+ import { type IScheduleRecord , ScheduleType } from "~/scheduler/types.js" ;
7
+ import { createScheduleRecord } from "~/scheduler/ScheduleRecord.js" ;
8
+ import { createMockGetIdentity } from "~tests/mocks/getIdentity.js" ;
6
9
7
10
describe ( "ScheduleExecutor" , ( ) => {
8
11
const service = createMockService ( ) ;
9
12
const scheduleModel = createMockScheduleModel ( ) ;
10
13
const cms = createMockCms ( ) ;
11
- const fetcher = createMockFetcher ( ) ;
12
14
13
15
it ( "should execute not find action for publishing" , async ( ) => {
16
+ const fetcher = createMockFetcher ( {
17
+ async getScheduled ( targetId : string ) : Promise < IScheduleRecord > {
18
+ return createScheduleRecord ( {
19
+ id : `schedule-record-id-${ targetId } ` ,
20
+ targetId,
21
+ scheduledOn : new Date ( ) ,
22
+ dateOn : new Date ( ) ,
23
+ type : ScheduleType . publish ,
24
+ title : `Scheduled for ${ targetId } ` ,
25
+ scheduledBy : createMockGetIdentity ( ) ( ) ,
26
+ model : { } as any
27
+ } ) ;
28
+ }
29
+ } ) ;
14
30
const executor = new ScheduleExecutor ( {
15
31
actions : [ ] ,
16
32
scheduleModel,
@@ -21,13 +37,31 @@ describe("ScheduleExecutor", () => {
21
37
22
38
await expect (
23
39
executor . schedule ( "target-id#0001" , {
24
- type : " publish" ,
25
- dateOn : new Date ( )
40
+ type : ScheduleType . publish ,
41
+ scheduleOn : new Date ( )
26
42
} )
27
- ) . rejects . toThrow ( `No action found for input type "publish"` ) ;
43
+ ) . rejects . toThrow ( `No action found for input type "${ ScheduleType . publish } "` ) ;
44
+
45
+ await expect ( executor . cancel ( "target-id#0001" ) ) . rejects . toThrow (
46
+ `No action found for input type "${ ScheduleType . publish } "`
47
+ ) ;
28
48
} ) ;
29
49
30
50
it ( "should execute not find action for unpublishing" , async ( ) => {
51
+ const fetcher = createMockFetcher ( {
52
+ async getScheduled ( targetId : string ) : Promise < IScheduleRecord > {
53
+ return createScheduleRecord ( {
54
+ id : `schedule-record-id-${ targetId } ` ,
55
+ targetId,
56
+ scheduledOn : new Date ( ) ,
57
+ dateOn : new Date ( ) ,
58
+ type : ScheduleType . unpublish ,
59
+ title : `Scheduled for ${ targetId } ` ,
60
+ scheduledBy : createMockGetIdentity ( ) ( ) ,
61
+ model : { } as any
62
+ } ) ;
63
+ }
64
+ } ) ;
31
65
const executor = new ScheduleExecutor ( {
32
66
actions : [ ] ,
33
67
scheduleModel,
@@ -38,9 +72,13 @@ describe("ScheduleExecutor", () => {
38
72
39
73
await expect (
40
74
executor . schedule ( "target-id#0001" , {
41
- type : " unpublish" ,
42
- dateOn : new Date ( )
75
+ type : ScheduleType . unpublish ,
76
+ scheduleOn : new Date ( )
43
77
} )
44
- ) . rejects . toThrow ( `No action found for input type "unpublish"` ) ;
78
+ ) . rejects . toThrow ( `No action found for input type "${ ScheduleType . unpublish } "` ) ;
79
+
80
+ await expect ( executor . cancel ( "target-id#0001" ) ) . rejects . toThrow (
81
+ `No action found for input type "${ ScheduleType . unpublish } "`
82
+ ) ;
45
83
} ) ;
46
84
} ) ;
0 commit comments