@@ -15,6 +15,41 @@ beforeAll(async () => {
1515
1616installProviderHttpMockCleanup ( ) ;
1717
18+ function firstPostJsonRequest ( ) {
19+ const [ call ] = postJsonRequestMock . mock . calls ;
20+ if ( ! call ) {
21+ throw new Error ( "expected Runway create request" ) ;
22+ }
23+ const [ request ] = call ;
24+ if ( ! request || typeof request !== "object" ) {
25+ throw new Error ( "expected Runway create request options" ) ;
26+ }
27+ return request as { url ?: string ; body ?: Record < string , unknown > } ;
28+ }
29+
30+ function firstFetchWithTimeoutCall ( ) {
31+ const [ call ] = fetchWithTimeoutMock . mock . calls ;
32+ if ( ! call ) {
33+ throw new Error ( "expected Runway poll request" ) ;
34+ }
35+ const [ url , init , timeoutMs , requestFetch ] = call ;
36+ if ( typeof url !== "string" ) {
37+ throw new Error ( "expected Runway poll request URL" ) ;
38+ }
39+ if ( ! init || typeof init !== "object" || Array . isArray ( init ) ) {
40+ throw new Error ( "expected Runway poll request init" ) ;
41+ }
42+ if ( typeof timeoutMs !== "number" ) {
43+ throw new Error ( "expected Runway poll request timeout" ) ;
44+ }
45+ return {
46+ init : init as { method ?: string ; headers ?: unknown } ,
47+ requestFetch,
48+ timeoutMs,
49+ url,
50+ } ;
51+ }
52+
1853describe ( "runway video generation provider" , ( ) => {
1954 it ( "declares explicit mode capabilities" , ( ) => {
2055 expectExplicitVideoGenerationCapabilities ( buildRunwayVideoGenerationProvider ( ) ) ;
@@ -54,23 +89,20 @@ describe("runway video generation provider", () => {
5489 } ) ;
5590
5691 expect ( postJsonRequestMock ) . toHaveBeenCalledTimes ( 1 ) ;
57- const createRequest = postJsonRequestMock . mock . calls [ 0 ] ?. [ 0 ] as
58- | { url ?: string ; body ?: unknown }
59- | undefined ;
60- expect ( createRequest ?. url ) . toBe ( "https://api.dev.runwayml.com/v1/text_to_video" ) ;
61- expect ( createRequest ?. body ) . toEqual ( {
92+ const createRequest = firstPostJsonRequest ( ) ;
93+ expect ( createRequest . url ) . toBe ( "https://api.dev.runwayml.com/v1/text_to_video" ) ;
94+ expect ( createRequest . body ) . toEqual ( {
6295 model : "gen4.5" ,
6396 promptText : "a tiny lobster DJ under neon lights" ,
6497 ratio : "1280:720" ,
6598 duration : 4 ,
6699 } ) ;
67- const pollCall = fetchWithTimeoutMock . mock . calls [ 0 ] ;
68- expect ( pollCall ?. [ 0 ] ) . toBe ( "https://api.dev.runwayml.com/v1/tasks/task-1" ) ;
69- const pollInit = pollCall ?. [ 1 ] as { method ?: string ; headers ?: unknown } | undefined ;
70- expect ( pollInit ?. method ) . toBe ( "GET" ) ;
71- expect ( pollInit ?. headers ) . toBeInstanceOf ( Headers ) ;
72- expect ( pollCall ?. [ 2 ] ) . toBe ( 120000 ) ;
73- expect ( pollCall ?. [ 3 ] ) . toBe ( fetch ) ;
100+ const pollCall = firstFetchWithTimeoutCall ( ) ;
101+ expect ( pollCall . url ) . toBe ( "https://api.dev.runwayml.com/v1/tasks/task-1" ) ;
102+ expect ( pollCall . init . method ) . toBe ( "GET" ) ;
103+ expect ( pollCall . init . headers ) . toBeInstanceOf ( Headers ) ;
104+ expect ( pollCall . timeoutMs ) . toBe ( 120000 ) ;
105+ expect ( pollCall . requestFetch ) . toBe ( fetch ) ;
74106 expect ( result . videos ) . toHaveLength ( 1 ) ;
75107 const video = result . videos [ 0 ] ;
76108 if ( ! video ) {
@@ -116,13 +148,11 @@ describe("runway video generation provider", () => {
116148 } ) ;
117149
118150 expect ( postJsonRequestMock ) . toHaveBeenCalledTimes ( 1 ) ;
119- const request = postJsonRequestMock . mock . calls [ 0 ] ?. [ 0 ] as
120- | { url ?: string ; body ?: Record < string , unknown > }
121- | undefined ;
122- expect ( request ?. url ) . toBe ( "https://api.dev.runwayml.com/v1/image_to_video" ) ;
123- expect ( request ?. body ?. promptImage ) . toMatch ( / ^ d a t a : i m a g e \/ p n g ; b a s e 6 4 , / u) ;
124- expect ( request ?. body ?. ratio ) . toBe ( "960:960" ) ;
125- expect ( request ?. body ?. duration ) . toBe ( 6 ) ;
151+ const request = firstPostJsonRequest ( ) ;
152+ expect ( request . url ) . toBe ( "https://api.dev.runwayml.com/v1/image_to_video" ) ;
153+ expect ( request . body ?. promptImage ) . toMatch ( / ^ d a t a : i m a g e \/ p n g ; b a s e 6 4 , / u) ;
154+ expect ( request . body ?. ratio ) . toBe ( "960:960" ) ;
155+ expect ( request . body ?. duration ) . toBe ( 6 ) ;
126156 } ) ;
127157
128158 it ( "requires gen4_aleph for video-to-video" , async ( ) => {
0 commit comments