@@ -369,14 +369,108 @@ describe("vectorize commands", () => {
369369 expect ( std . warn ) . toMatchInlineSnapshot ( `
370370 "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m[0m
371371
372- You haven't created any indexes on this account.
372+ You haven't created any indexes on this account.
373373
374- Use 'wrangler vectorize create <name>' to create one, or visit
375- [4mhttps://developers.cloudflare.com/vectorize/[0m to get started.
374+ Use 'wrangler vectorize create <name>' to create one, or visit
375+ [4mhttps://developers.cloudflare.com/vectorize/[0m to get started.
376376
377377
378- "
378+ "
379+ ` ) ;
380+ } ) ;
381+
382+ it ( "should return empty array JSON when there are no vectorize indexes with --json flag" , async ( ) => {
383+ mockVectorizeV2RequestError ( ) ;
384+ await runWrangler ( "vectorize list --json" ) ;
385+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `[]` ) ;
386+ expect ( std . warn ) . toBe ( "" ) ;
387+ expect ( std . err ) . toBe ( "" ) ;
388+ } ) ;
389+
390+ it ( "should handle listing vectorize indexes with valid JSON output" , async ( ) => {
391+ mockVectorizeV2Request ( ) ;
392+ await runWrangler ( "vectorize list --json" ) ;
393+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
394+ [
395+ {
396+ "config": {
397+ "dimensions": 1536,
398+ "metric": "euclidean",
399+ },
400+ "created_on": "2024-07-11T13:02:18.00268Z",
401+ "description": "test-desc",
402+ "modified_on": "2024-07-11T13:02:18.00268Z",
403+ "name": "test-index",
404+ },
405+ {
406+ "config": {
407+ "dimensions": 32,
408+ "metric": "dot-product",
409+ },
410+ "created_on": "2024-07-11T13:02:18.00268Z",
411+ "description": "another-desc",
412+ "modified_on": "2024-07-11T13:02:18.00268Z",
413+ "name": "another-index",
414+ },
415+ ]
416+ ` ) ;
417+ expect ( std . warn ) . toBe ( "" ) ;
418+ expect ( std . err ) . toBe ( "" ) ;
419+ } ) ;
420+
421+ it ( "should handle creating a vectorize index with valid JSON output" , async ( ) => {
422+ mockVectorizeV2Request ( ) ;
423+ await runWrangler (
424+ "vectorize create test-index --dimensions=1536 --metric=euclidean --json"
425+ ) ;
426+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
427+ {
428+ "config": {
429+ "dimensions": 1536,
430+ "metric": "euclidean",
431+ },
432+ "created_on": "2024-07-11T13:02:18.00268Z",
433+ "description": "test-desc",
434+ "modified_on": "2024-07-11T13:02:18.00268Z",
435+ "name": "test-index",
436+ }
437+ ` ) ;
438+ expect ( std . warn ) . toBe ( "" ) ;
439+ expect ( std . err ) . toBe ( "" ) ;
440+ } ) ;
441+
442+ it ( "should handle get on a vectorize index with valid JSON output" , async ( ) => {
443+ mockVectorizeV2Request ( ) ;
444+ await runWrangler ( "vectorize get test-index --json" ) ;
445+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
446+ {
447+ "config": {
448+ "dimensions": 1536,
449+ "metric": "euclidean",
450+ },
451+ "created_on": "2024-07-11T13:02:18.00268Z",
452+ "description": "test-desc",
453+ "modified_on": "2024-07-11T13:02:18.00268Z",
454+ "name": "test-index",
455+ }
379456 ` ) ;
457+ expect ( std . warn ) . toBe ( "" ) ;
458+ expect ( std . err ) . toBe ( "" ) ;
459+ } ) ;
460+
461+ it ( "should handle info on a vectorize index with valid JSON output" , async ( ) => {
462+ mockVectorizeV2Request ( ) ;
463+ await runWrangler ( "vectorize info test-index --json" ) ;
464+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
465+ {
466+ "dimensions": 1024,
467+ "processedUpToDatetime": "2024-07-19T13:11:44.064Z",
468+ "processedUpToMutation": "7f11d6e5-d126-4f76-936e-fbfec079e0be",
469+ "vectorCount": 1000,
470+ }
471+ ` ) ;
472+ expect ( std . warn ) . toBe ( "" ) ;
473+ expect ( std . err ) . toBe ( "" ) ;
380474 } ) ;
381475
382476 it ( "should handle a get on a vectorize V1 index" , async ( ) => {
@@ -869,14 +963,45 @@ describe("vectorize commands", () => {
869963 expect ( std . warn ) . toMatchInlineSnapshot ( `
870964 "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m[0m
871965
872- You haven't created any metadata indexes on this account.
966+ You haven't created any metadata indexes on this account.
873967
874- Use 'wrangler vectorize create-metadata-index <name>' to create one, or visit
875- [4mhttps://developers.cloudflare.com/vectorize/[0m to get started.
968+ Use 'wrangler vectorize create-metadata-index <name>' to create one, or visit
969+ [4mhttps://developers.cloudflare.com/vectorize/[0m to get started.
876970
877971
878- "
972+ "
973+ ` ) ;
974+ } ) ;
975+
976+ it ( "should return empty array JSON when list metadata indexes returns empty with --json flag" , async ( ) => {
977+ mockVectorizeV2RequestError ( ) ;
978+ await runWrangler ( "vectorize list-metadata-index test-index --json" ) ;
979+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `[]` ) ;
980+ expect ( std . warn ) . toBe ( "" ) ;
981+ expect ( std . err ) . toBe ( "" ) ;
982+ } ) ;
983+
984+ it ( "should handle list-metadata-index with valid JSON output" , async ( ) => {
985+ mockVectorizeV2Request ( ) ;
986+ await runWrangler ( "vectorize list-metadata-index test-index --json" ) ;
987+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
988+ [
989+ {
990+ "indexType": "string",
991+ "propertyName": "string-prop",
992+ },
993+ {
994+ "indexType": "number",
995+ "propertyName": "num-prop",
996+ },
997+ {
998+ "indexType": "boolean",
999+ "propertyName": "bool-prop",
1000+ },
1001+ ]
8791002 ` ) ;
1003+ expect ( std . warn ) . toBe ( "" ) ;
1004+ expect ( std . err ) . toBe ( "" ) ;
8801005 } ) ;
8811006
8821007 it ( "should handle delete metadata index" , async ( ) => {
@@ -1025,6 +1150,8 @@ describe("vectorize commands", () => {
10251150 ],
10261151 }
10271152 ` ) ;
1153+ expect ( std . warn ) . toBe ( "" ) ;
1154+ expect ( std . err ) . toBe ( "" ) ;
10281155 } ) ;
10291156
10301157 it ( "should warn when list-vectors returns no vectors" , async ( ) => {
@@ -1040,8 +1167,25 @@ describe("vectorize commands", () => {
10401167 expect ( std . warn ) . toMatchInlineSnapshot ( `
10411168 "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mNo vectors found in this index.[0m
10421169
1043- "
1170+ "
1171+ ` ) ;
1172+ } ) ;
1173+
1174+ it ( "should return valid JSON when list-vectors returns no vectors with --json flag" , async ( ) => {
1175+ mockVectorizeV2RequestError ( ) ;
1176+ await runWrangler ( "vectorize list-vectors test-index --json" ) ;
1177+ expect ( JSON . parse ( std . out ) ) . toMatchInlineSnapshot ( `
1178+ {
1179+ "count": 0,
1180+ "cursorExpirationTimestamp": null,
1181+ "isTruncated": false,
1182+ "nextCursor": null,
1183+ "totalCount": 0,
1184+ "vectors": [],
1185+ }
10441186 ` ) ;
1187+ expect ( std . warn ) . toBe ( "" ) ;
1188+ expect ( std . err ) . toBe ( "" ) ;
10451189 } ) ;
10461190} ) ;
10471191
0 commit comments