@@ -45,6 +45,26 @@ describe('ArtifactApi', () => {
4545 expect ( result . filename ) . toBe ( filename ) ;
4646 } ) ;
4747
48+ it ( 'should require filename parameter' , async ( ) => {
49+ const fileBlob = new Blob ( [ 'data' ] , { type : 'text/plain' } ) ;
50+
51+ await expect (
52+ api . uploadArtifact ( {
53+ filename : null as unknown as string ,
54+ file : fileBlob ,
55+ } )
56+ ) . rejects . toThrow ( ) ;
57+ } ) ;
58+
59+ it ( 'should require file parameter' , async ( ) => {
60+ await expect (
61+ api . uploadArtifact ( {
62+ filename : 'test.txt' ,
63+ file : null as unknown as Blob ,
64+ } )
65+ ) . rejects . toThrow ( ) ;
66+ } ) ;
67+
4868 it ( 'should attach artifact to a result' , async ( ) => {
4969 const fileBlob = new Blob ( [ 'data' ] , { type : 'text/plain' } ) ;
5070 const resultId = '123e4567-e89b-12d3-a456-426614174001' ;
@@ -405,7 +425,7 @@ describe('ArtifactApi', () => {
405425 } ) ;
406426
407427 describe ( 'authentication' , ( ) => {
408- it ( 'should include Bearer token when configured' , async ( ) => {
428+ it ( 'should include Bearer token when configured for getArtifact ' , async ( ) => {
409429 const config = new Configuration ( {
410430 basePath : 'http://localhost/api' ,
411431 accessToken : async ( ) => 'test-token-456' ,
@@ -437,6 +457,168 @@ describe('ArtifactApi', () => {
437457 ) ;
438458 } ) ;
439459
460+ it ( 'should include Bearer token when configured for uploadArtifact' , async ( ) => {
461+ const config = new Configuration ( {
462+ basePath : 'http://localhost/api' ,
463+ accessToken : async ( ) => 'test-token-upload' ,
464+ } ) ;
465+ api = new ArtifactApi ( config ) ;
466+
467+ const fileBlob = new Blob ( [ 'data' ] , { type : 'text/plain' } ) ;
468+ const responseArtifact : Artifact = {
469+ id : '123e4567-e89b-12d3-a456-426614174000' ,
470+ filename : 'test.txt' ,
471+ } ;
472+
473+ mockFetch = createMockFetch ( responseArtifact , 201 ) ;
474+ global . fetch = mockFetch ;
475+
476+ await api . uploadArtifact ( {
477+ filename : 'test.txt' ,
478+ file : fileBlob ,
479+ } ) ;
480+
481+ interface FetchOptions {
482+ method : string ;
483+ headers : Record < string , string > ;
484+ }
485+ expect ( mockFetch ) . toHaveBeenCalledWith (
486+ expect . any ( String ) ,
487+ expect . objectContaining < Partial < FetchOptions > > ( {
488+ headers : expect . objectContaining < Record < string , string > > ( {
489+ Authorization : 'Bearer test-token-upload' ,
490+ } ) ,
491+ } )
492+ ) ;
493+ } ) ;
494+
495+ it ( 'should include Bearer token when configured for getArtifactList' , async ( ) => {
496+ const config = new Configuration ( {
497+ basePath : 'http://localhost/api' ,
498+ accessToken : async ( ) => 'test-token-list' ,
499+ } ) ;
500+ api = new ArtifactApi ( config ) ;
501+
502+ const mockArtifactList : ArtifactList = {
503+ artifacts : [ ] ,
504+ pagination : {
505+ page : 1 ,
506+ pageSize : 25 ,
507+ totalItems : 0 ,
508+ totalPages : 0 ,
509+ } ,
510+ } ;
511+
512+ mockFetch = createMockFetch ( mockArtifactList ) ;
513+ global . fetch = mockFetch ;
514+
515+ await api . getArtifactList ( { } ) ;
516+
517+ interface FetchOptions {
518+ method : string ;
519+ headers : Record < string , string > ;
520+ }
521+ expect ( mockFetch ) . toHaveBeenCalledWith (
522+ expect . any ( String ) ,
523+ expect . objectContaining < Partial < FetchOptions > > ( {
524+ headers : expect . objectContaining < Record < string , string > > ( {
525+ Authorization : 'Bearer test-token-list' ,
526+ } ) ,
527+ } )
528+ ) ;
529+ } ) ;
530+
531+ it ( 'should include Bearer token when configured for deleteArtifact' , async ( ) => {
532+ const config = new Configuration ( {
533+ basePath : 'http://localhost/api' ,
534+ accessToken : async ( ) => 'test-token-delete' ,
535+ } ) ;
536+ api = new ArtifactApi ( config ) ;
537+
538+ mockFetch = jest . fn ( ) . mockResolvedValue ( {
539+ ok : true ,
540+ status : 204 ,
541+ } ) ;
542+ global . fetch = mockFetch ;
543+
544+ await api . deleteArtifact ( { id : '123e4567-e89b-12d3-a456-426614174000' } ) ;
545+
546+ interface FetchOptions {
547+ method : string ;
548+ headers : Record < string , string > ;
549+ }
550+ expect ( mockFetch ) . toHaveBeenCalledWith (
551+ expect . any ( String ) ,
552+ expect . objectContaining < Partial < FetchOptions > > ( {
553+ headers : expect . objectContaining < Record < string , string > > ( {
554+ Authorization : 'Bearer test-token-delete' ,
555+ } ) ,
556+ } )
557+ ) ;
558+ } ) ;
559+
560+ it ( 'should include Bearer token when configured for downloadArtifact' , async ( ) => {
561+ const config = new Configuration ( {
562+ basePath : 'http://localhost/api' ,
563+ accessToken : async ( ) => 'test-token-download' ,
564+ } ) ;
565+ api = new ArtifactApi ( config ) ;
566+
567+ const mockBlob = new Blob ( [ 'file content' ] , { type : 'text/plain' } ) ;
568+ mockFetch = jest . fn ( ) . mockResolvedValue ( {
569+ ok : true ,
570+ status : 200 ,
571+ blob : async ( ) => mockBlob ,
572+ } ) ;
573+ global . fetch = mockFetch ;
574+
575+ await api . downloadArtifact ( { id : '123e4567-e89b-12d3-a456-426614174000' } ) ;
576+
577+ interface FetchOptions {
578+ method : string ;
579+ headers : Record < string , string > ;
580+ }
581+ expect ( mockFetch ) . toHaveBeenCalledWith (
582+ expect . any ( String ) ,
583+ expect . objectContaining < Partial < FetchOptions > > ( {
584+ headers : expect . objectContaining < Record < string , string > > ( {
585+ Authorization : 'Bearer test-token-download' ,
586+ } ) ,
587+ } )
588+ ) ;
589+ } ) ;
590+
591+ it ( 'should include Bearer token when configured for viewArtifact' , async ( ) => {
592+ const config = new Configuration ( {
593+ basePath : 'http://localhost/api' ,
594+ accessToken : async ( ) => 'test-token-view' ,
595+ } ) ;
596+ api = new ArtifactApi ( config ) ;
597+
598+ const mockBlob = new Blob ( [ '<html>content</html>' ] , { type : 'text/html' } ) ;
599+ mockFetch = jest . fn ( ) . mockResolvedValue ( {
600+ ok : true ,
601+ status : 200 ,
602+ blob : async ( ) => mockBlob ,
603+ } ) ;
604+ global . fetch = mockFetch ;
605+
606+ await api . viewArtifact ( { id : '123e4567-e89b-12d3-a456-426614174000' } ) ;
607+
608+ interface FetchOptions {
609+ method : string ;
610+ headers : Record < string , string > ;
611+ }
612+ expect ( mockFetch ) . toHaveBeenCalledWith (
613+ expect . any ( String ) ,
614+ expect . objectContaining < Partial < FetchOptions > > ( {
615+ headers : expect . objectContaining < Record < string , string > > ( {
616+ Authorization : 'Bearer test-token-view' ,
617+ } ) ,
618+ } )
619+ ) ;
620+ } ) ;
621+
440622 it ( 'should work without authentication when not configured' , async ( ) => {
441623 const artifactId = '123e4567-e89b-12d3-a456-426614174000' ;
442624 const expectedArtifact : Artifact = {
0 commit comments