@@ -28,11 +28,12 @@ import (
2828 "riverqueue.com/riverui/internal/riverinternaltest"
2929 "riverqueue.com/riverui/internal/riverinternaltest/testfactory"
3030 "riverqueue.com/riverui/internal/uicommontest"
31+ "riverqueue.com/riverui/riverproui/internal/protestfactory"
3132)
3233
3334type setupEndpointTestBundle struct {
3435 client * riverpro.Client [pgx.Tx ]
35- exec riverdriver. ExecutorTx
36+ exec driver. ProExecutorTx
3637 logger * slog.Logger
3738 tx pgx.Tx
3839}
@@ -101,6 +102,41 @@ func testMountOpts(t *testing.T) *apiendpoint.MountOpts {
101102 }
102103}
103104
105+ func TestProAPIHandlerPeriodicJobList (t * testing.T ) {
106+ t .Parallel ()
107+
108+ ctx := context .Background ()
109+
110+ t .Run ("Success" , func (t * testing.T ) {
111+ t .Parallel ()
112+
113+ endpoint , bundle := setupEndpoint (ctx , t , NewPeriodicJobListEndpoint )
114+
115+ job1 := protestfactory .PeriodicJob (ctx , t , bundle .exec , & protestfactory.PeriodicJobOpts {ID : ptrutil .Ptr ("alpha" ), NextRunAt : ptrutil .Ptr (time .Now ().Add (time .Minute ))})
116+ job2 := protestfactory .PeriodicJob (ctx , t , bundle .exec , & protestfactory.PeriodicJobOpts {ID : ptrutil .Ptr ("beta" ), NextRunAt : ptrutil .Ptr (time .Now ().Add (2 * time .Minute ))})
117+
118+ resp , err := apitest .InvokeHandler (ctx , endpoint .Execute , testMountOpts (t ), & periodicJobListRequest {})
119+ require .NoError (t , err )
120+ require .Len (t , resp .Data , 2 )
121+ require .Equal (t , job1 .ID , resp .Data [0 ].ID )
122+ require .Equal (t , job2 .ID , resp .Data [1 ].ID )
123+ })
124+
125+ t .Run ("Limit" , func (t * testing.T ) {
126+ t .Parallel ()
127+
128+ endpoint , bundle := setupEndpoint (ctx , t , NewPeriodicJobListEndpoint )
129+
130+ job1 := protestfactory .PeriodicJob (ctx , t , bundle .exec , nil )
131+ _ = protestfactory .PeriodicJob (ctx , t , bundle .exec , nil )
132+
133+ resp , err := apitest .InvokeHandler (ctx , endpoint .Execute , testMountOpts (t ), & periodicJobListRequest {Limit : ptrutil .Ptr (1 )})
134+ require .NoError (t , err )
135+ require .Len (t , resp .Data , 1 )
136+ require .Equal (t , job1 .ID , resp .Data [0 ].ID )
137+ })
138+ }
139+
104140func TestProAPIHandlerWorkflowCancel (t * testing.T ) {
105141 t .Parallel ()
106142
0 commit comments