@@ -60,17 +60,15 @@ describe('ExportAssets', () => {
6060 } ) ;
6161
6262 describe ( 'start method' , ( ) => {
63- it ( 'should fetch folders and assets in parallel ' , async ( ) => {
63+ it ( 'should fetch folders and assets using the workspace space_uid ' , async ( ) => {
6464 const foldersStub = sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
6565 const assetsStub = sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( emptyAssetsResponse ) ;
6666
6767 const exporter = new ExportAssets ( apiConfig , exportContext ) ;
6868 await exporter . start ( workspace , spaceDir ) ;
6969
70- expect ( foldersStub . calledOnce ) . to . be . true ;
71- expect ( foldersStub . calledWith ( workspace . space_uid ) ) . to . be . true ;
72- expect ( assetsStub . calledOnce ) . to . be . true ;
73- expect ( assetsStub . calledWith ( workspace . space_uid ) ) . to . be . true ;
70+ expect ( foldersStub . firstCall . args [ 0 ] ) . to . equal ( workspace . space_uid ) ;
71+ expect ( assetsStub . firstCall . args [ 0 ] ) . to . equal ( workspace . space_uid ) ;
7472 } ) ;
7573
7674 it ( 'should write chunked assets metadata with correct args' , async ( ) => {
@@ -82,27 +80,27 @@ describe('ExportAssets', () => {
8280 await exporter . start ( workspace , spaceDir ) ;
8381
8482 const writeStub = ( AssetManagementExportAdapter . prototype as any ) . writeItemsToChunkedJson as sinon . SinonStub ;
85- expect ( writeStub . calledOnce ) . to . be . true ;
8683 const args = writeStub . firstCall . args ;
8784 expect ( args [ 1 ] ) . to . equal ( 'assets.json' ) ;
8885 expect ( args [ 2 ] ) . to . equal ( 'assets' ) ;
8986 expect ( args [ 3 ] ) . to . deep . equal ( [ 'uid' , 'url' , 'filename' , 'file_name' , 'parent_uid' ] ) ;
9087 expect ( args [ 4 ] ) . to . have . length ( 2 ) ;
9188 } ) ;
9289
93- it ( 'should skip downloads when no asset items exist ' , async ( ) => {
90+ it ( 'should not attempt any downloads when the asset list is empty ' , async ( ) => {
9491 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
9592 sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( emptyAssetsResponse ) ;
9693
9794 const exporter = new ExportAssets ( apiConfig , exportContext ) ;
9895 await exporter . start ( workspace , spaceDir ) ;
9996
97+ expect ( fetchStub . callCount ) . to . equal ( 0 ) ;
10098 const tickStub = ( AssetManagementExportAdapter . prototype as any ) . tick as sinon . SinonStub ;
10199 const downloadTick = tickStub . getCalls ( ) . find ( ( c ) => String ( c . args [ 1 ] ) . startsWith ( 'downloads:' ) ) ;
102100 expect ( downloadTick ) . to . be . undefined ;
103101 } ) ;
104102
105- it ( 'should handle download failures gracefully without throwing ' , async ( ) => {
103+ it ( 'should tick with success=false and the error message on download failure ' , async ( ) => {
106104 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
107105 sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( assetsResponseWithItems ) ;
108106 fetchStub . rejects ( new Error ( 'network failure' ) ) ;
@@ -112,12 +110,11 @@ describe('ExportAssets', () => {
112110
113111 const tickStub = ( AssetManagementExportAdapter . prototype as any ) . tick as sinon . SinonStub ;
114112 const downloadTick = tickStub . getCalls ( ) . find ( ( c ) => String ( c . args [ 1 ] ) . startsWith ( 'downloads:' ) ) ;
115- expect ( downloadTick ) . to . not . be . undefined ;
116113 expect ( downloadTick ! . args [ 0 ] ) . to . be . false ;
117114 expect ( downloadTick ! . args [ 2 ] ) . to . equal ( 'network failure' ) ;
118115 } ) ;
119116
120- it ( 'should tick success for downloads when all succeed ' , async ( ) => {
117+ it ( 'should tick with success=true and null error on successful downloads ' , async ( ) => {
121118 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
122119 sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( assetsResponseWithItems ) ;
123120 fetchStub . callsFake ( async ( ) => makeFetchResponse ( ) as any ) ;
@@ -127,12 +124,11 @@ describe('ExportAssets', () => {
127124
128125 const tickStub = ( AssetManagementExportAdapter . prototype as any ) . tick as sinon . SinonStub ;
129126 const downloadTick = tickStub . getCalls ( ) . find ( ( c ) => String ( c . args [ 1 ] ) . startsWith ( 'downloads:' ) ) ;
130- expect ( downloadTick ) . to . not . be . undefined ;
131127 expect ( downloadTick ! . args [ 0 ] ) . to . be . true ;
132128 expect ( downloadTick ! . args [ 2 ] ) . to . be . null ;
133129 } ) ;
134130
135- it ( 'should skip assets with no url or uid' , async ( ) => {
131+ it ( 'should skip assets that have neither a url nor a uid' , async ( ) => {
136132 const incompleteAssets = {
137133 items : [
138134 { uid : 'a1' , url : null as any } ,
@@ -146,10 +142,10 @@ describe('ExportAssets', () => {
146142 const exporter = new ExportAssets ( apiConfig , exportContext ) ;
147143 await exporter . start ( workspace , spaceDir ) ;
148144
149- expect ( fetchStub . called ) . to . be . false ;
145+ expect ( fetchStub . callCount ) . to . equal ( 0 ) ;
150146 } ) ;
151147
152- it ( 'should use _uid when uid is not present on asset ' , async ( ) => {
148+ it ( 'should process assets that have _uid instead of uid without skipping them ' , async ( ) => {
153149 const assetsWithUnderscoreUid = {
154150 items : [ { _uid : 'a-uid' , url : 'https://cdn.example.com/a.png' , filename : 'a.png' } ] ,
155151 } ;
@@ -160,17 +156,18 @@ describe('ExportAssets', () => {
160156 const exporter = new ExportAssets ( apiConfig , exportContext ) ;
161157 await exporter . start ( workspace , spaceDir ) ;
162158
159+ expect ( fetchStub . firstCall . args [ 0 ] ) . to . equal ( 'https://cdn.example.com/a.png' ) ;
163160 const tickStub = ( AssetManagementExportAdapter . prototype as any ) . tick as sinon . SinonStub ;
164161 const downloadTick = tickStub . getCalls ( ) . find ( ( c ) => String ( c . args [ 1 ] ) . startsWith ( 'downloads:' ) ) ;
165- expect ( downloadTick ) . to . not . be . undefined ;
166162 expect ( downloadTick ! . args [ 0 ] ) . to . be . true ;
163+ expect ( downloadTick ! . args [ 2 ] ) . to . be . null ;
167164 } ) ;
168165
169- it ( 'should use file_name when filename is not present, defaulting to "asset"' , async ( ) => {
166+ it ( 'should download assets that use file_name, and fall back to "asset" when both names are absent ' , async ( ) => {
170167 const assetsNoFilename = {
171168 items : [
172- { uid : 'a1' , url : 'https://cdn.example.com/a1' , file_name : 'named.pdf' } ,
173- { uid : 'a2' , url : 'https://cdn.example.com/a2' } ,
169+ { uid : 'a1' , url : 'https://cdn.example.com/a1.pdf ' , file_name : 'named.pdf' } ,
170+ { uid : 'a2' , url : 'https://cdn.example.com/a2.bin ' } ,
174171 ] ,
175172 } ;
176173 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
@@ -181,6 +178,11 @@ describe('ExportAssets', () => {
181178 await exporter . start ( workspace , spaceDir ) ;
182179
183180 expect ( fetchStub . callCount ) . to . equal ( 2 ) ;
181+ expect ( fetchStub . firstCall . args [ 0 ] ) . to . equal ( 'https://cdn.example.com/a1.pdf' ) ;
182+ expect ( fetchStub . secondCall . args [ 0 ] ) . to . equal ( 'https://cdn.example.com/a2.bin' ) ;
183+ const tickStub = ( AssetManagementExportAdapter . prototype as any ) . tick as sinon . SinonStub ;
184+ const downloadTick = tickStub . getCalls ( ) . find ( ( c ) => String ( c . args [ 1 ] ) . startsWith ( 'downloads:' ) ) ;
185+ expect ( downloadTick ! . args [ 0 ] ) . to . be . true ;
184186 } ) ;
185187
186188 it ( 'should append authtoken to URL when securedAssets is true' , async ( ) => {
@@ -215,7 +217,7 @@ describe('ExportAssets', () => {
215217 expect ( downloadUrl ) . to . include ( '?v=1&authtoken=' ) ;
216218 } ) ;
217219
218- it ( 'should handle non-ok HTTP response as download failure ' , async ( ) => {
220+ it ( 'should tick with success=false and the HTTP status code on non-ok response ' , async ( ) => {
219221 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
220222 sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( {
221223 items : [ { uid : 'a1' , url : 'https://cdn.example.com/a1.png' , filename : 'img.png' } ] ,
@@ -231,7 +233,7 @@ describe('ExportAssets', () => {
231233 expect ( downloadTick ! . args [ 2 ] ) . to . include ( '403' ) ;
232234 } ) ;
233235
234- it ( 'should handle missing response body as download failure ' , async ( ) => {
236+ it ( 'should tick with success=false and "No response body" when body is null ' , async ( ) => {
235237 sinon . stub ( ExportAssets . prototype , 'getWorkspaceFolders' ) . resolves ( foldersData ) ;
236238 sinon . stub ( ExportAssets . prototype , 'getWorkspaceAssets' ) . resolves ( {
237239 items : [ { uid : 'a1' , url : 'https://cdn.example.com/a1.png' , filename : 'img.png' } ] ,
0 commit comments