@@ -14,6 +14,12 @@ jest.mock('../../http');
1414const mockValidateFileInput = inputsModule . validateFileInput as jest . MockedFunction <
1515 typeof inputsModule . validateFileInput
1616> ;
17+ const mockIsRemoteFileInput = inputsModule . isRemoteFileInput as jest . MockedFunction <
18+ typeof inputsModule . isRemoteFileInput
19+ > ;
20+ const mockGetRemoteUrl = inputsModule . getRemoteUrl as jest . MockedFunction <
21+ typeof inputsModule . getRemoteUrl
22+ > ;
1723const mockSendRequest = httpModule . sendRequest as jest . MockedFunction <
1824 typeof httpModule . sendRequest
1925> ;
@@ -31,6 +37,8 @@ describe('WorkflowBuilder', () => {
3137 workflow = new WorkflowBuilder ( mockClientOptions ) ;
3238 // Default mocks
3339 mockValidateFileInput . mockReturnValue ( true ) ;
40+ mockIsRemoteFileInput . mockReturnValue ( false ) ;
41+ mockGetRemoteUrl . mockReturnValue ( null ) ; // Default: not a URL
3442 mockSendRequest . mockResolvedValue ( {
3543 data : new Blob ( [ 'mock response' ] , { type : 'application/pdf' } ) as never ,
3644 status : 200 ,
@@ -102,20 +110,16 @@ describe('WorkflowBuilder', () => {
102110 expect ( result ) . toBe ( workflow ) ;
103111 } ) ;
104112
105- it ( 'should not call registerAssets when adding a file as a URL string' , ( ) => {
106- // Mock isRemoteFileInput to return true for URL string
107- jest . spyOn ( inputsModule , 'isRemoteFileInput' ) . mockReturnValueOnce ( true ) ;
108-
109- // Create a spy on the registerAssets method
110- const registerAssetsSpy = jest . spyOn ( workflow as never , 'registerAssets' ) ;
111-
113+ it ( 'should handle URL string input without adding to assets map' , ( ) => {
112114 const urlString = 'https://example.com/document.pdf' ;
115+ // Mock getRemoteUrl to return the URL (indicating it's a remote file)
116+ mockGetRemoteUrl . mockReturnValueOnce ( urlString ) ;
117+
113118 const result = workflow . addFilePart ( urlString ) ;
114119
115120 expect ( result ) . toBe ( workflow ) ;
116- expect ( registerAssetsSpy ) . not . toHaveBeenCalled ( ) ;
117121
118- // Verify the file part was added with the URL
122+ // Verify the file part was added with the URL (not stored in assets)
119123 expect (
120124 workflow [ 'buildInstructions' ] . parts [ workflow [ 'buildInstructions' ] . parts . length - 1 ] ,
121125 ) . toEqual (
@@ -124,21 +128,18 @@ describe('WorkflowBuilder', () => {
124128 } ) ,
125129 ) ;
126130
127- registerAssetsSpy . mockRestore ( ) ;
131+ // Verify no assets were registered (URLs are passed directly)
132+ expect ( workflow [ 'assets' ] . size ) . toBe ( 0 ) ;
128133 } ) ;
129134
130- it ( 'should not call registerAssets when adding a file as a URL object' , ( ) => {
131- // Mock isRemoteFileInput to return true for URL object
132- jest . spyOn ( inputsModule , 'isRemoteFileInput' ) . mockReturnValueOnce ( true ) ;
133-
134- // Create a spy on the registerAssets method
135- const registerAssetsSpy = jest . spyOn ( workflow as never , 'registerAssets' ) ;
136-
135+ it ( 'should handle URL object input without adding to assets map' , ( ) => {
137136 const urlObject : UrlInput = { type : 'url' , url : 'https://example.com/document.pdf' } ;
137+ // Mock getRemoteUrl to return the URL (indicating it's a remote file)
138+ mockGetRemoteUrl . mockReturnValueOnce ( urlObject . url ) ;
139+
138140 const result = workflow . addFilePart ( urlObject ) ;
139141
140142 expect ( result ) . toBe ( workflow ) ;
141- expect ( registerAssetsSpy ) . not . toHaveBeenCalled ( ) ;
142143
143144 // Verify the file part was added with the URL
144145 expect (
@@ -149,7 +150,8 @@ describe('WorkflowBuilder', () => {
149150 } ) ,
150151 ) ;
151152
152- registerAssetsSpy . mockRestore ( ) ;
153+ // Verify no assets were registered (URLs are passed directly)
154+ expect ( workflow [ 'assets' ] . size ) . toBe ( 0 ) ;
153155 } ) ;
154156 } ) ;
155157
@@ -171,18 +173,14 @@ describe('WorkflowBuilder', () => {
171173 expect ( result ) . toBe ( workflow ) ;
172174 } ) ;
173175
174- it ( 'should not call registerAssets when adding HTML as a URL string' , ( ) => {
175- // Mock isRemoteFileInput to return true for URL string
176- jest . spyOn ( inputsModule , 'isRemoteFileInput' ) . mockReturnValueOnce ( true ) ;
177-
178- // Create a spy on the registerAssets method
179- const registerAssetsSpy = jest . spyOn ( workflow as never , 'registerAssets' ) ;
180-
176+ it ( 'should handle HTML URL string input without adding to assets map' , ( ) => {
181177 const urlString = 'https://example.com/page.html' ;
178+ // Mock getRemoteUrl to return the URL (indicating it's a remote file)
179+ mockGetRemoteUrl . mockReturnValueOnce ( urlString ) ;
180+
182181 const result = workflow . addHtmlPart ( urlString ) ;
183182
184183 expect ( result ) . toBe ( workflow ) ;
185- expect ( registerAssetsSpy ) . not . toHaveBeenCalled ( ) ;
186184
187185 // Verify the HTML part was added with the URL
188186 expect (
@@ -193,21 +191,18 @@ describe('WorkflowBuilder', () => {
193191 } ) ,
194192 ) ;
195193
196- registerAssetsSpy . mockRestore ( ) ;
194+ // Verify no assets were registered (URLs are passed directly)
195+ expect ( workflow [ 'assets' ] . size ) . toBe ( 0 ) ;
197196 } ) ;
198197
199- it ( 'should not call registerAssets when adding HTML as a URL object' , ( ) => {
200- // Mock isRemoteFileInput to return true for URL object
201- jest . spyOn ( inputsModule , 'isRemoteFileInput' ) . mockReturnValueOnce ( true ) ;
202-
203- // Create a spy on the registerAssets method
204- const registerAssetsSpy = jest . spyOn ( workflow as never , 'registerAssets' ) ;
205-
198+ it ( 'should handle HTML URL object input without adding to assets map' , ( ) => {
206199 const urlObject : UrlInput = { type : 'url' , url : 'https://example.com/page.html' } ;
200+ // Mock getRemoteUrl to return the URL (indicating it's a remote file)
201+ mockGetRemoteUrl . mockReturnValueOnce ( urlObject . url ) ;
202+
207203 const result = workflow . addHtmlPart ( urlObject ) ;
208204
209205 expect ( result ) . toBe ( workflow ) ;
210- expect ( registerAssetsSpy ) . not . toHaveBeenCalled ( ) ;
211206
212207 // Verify the HTML part was added with the URL
213208 expect (
@@ -218,7 +213,8 @@ describe('WorkflowBuilder', () => {
218213 } ) ,
219214 ) ;
220215
221- registerAssetsSpy . mockRestore ( ) ;
216+ // Verify no assets were registered (URLs are passed directly)
217+ expect ( workflow [ 'assets' ] . size ) . toBe ( 0 ) ;
222218 } ) ;
223219 } ) ;
224220
@@ -274,6 +270,54 @@ describe('WorkflowBuilder', () => {
274270 expect ( result ) . toBe ( workflow ) ;
275271 expect ( mockValidateFileInput ) . toHaveBeenCalledWith ( xfdfFile ) ;
276272 } ) ;
273+
274+ it ( 'should handle URL input for watermarkImage action' , ( ) => {
275+ const urlInput : UrlInput = { type : 'url' , url : 'https://example.com/watermark.png' } ;
276+ const action = BuildActions . watermarkImage ( urlInput ) ;
277+
278+ // Mock getRemoteUrl: first call for test.pdf (returns null), second for URL action (returns URL)
279+ mockGetRemoteUrl . mockReturnValueOnce ( null ) . mockReturnValueOnce ( urlInput . url ) ;
280+
281+ workflow . addFilePart ( 'test.pdf' ) . applyAction ( action ) ;
282+
283+ // Verify the action's fileInput contains the URL
284+ expect ( action . fileInput ) . toEqual ( urlInput ) ;
285+
286+ // Verify only the test.pdf was registered as local asset (not the watermark URL)
287+ expect ( workflow [ 'assets' ] . size ) . toBe ( 1 ) ;
288+ } ) ;
289+
290+ it ( 'should handle URL input for applyInstantJson action' , ( ) => {
291+ const urlInput : UrlInput = { type : 'url' , url : 'https://example.com/annotations.json' } ;
292+ const action = BuildActions . applyInstantJson ( urlInput ) ;
293+
294+ // Mock getRemoteUrl: first call for test.pdf (returns null), second for URL action (returns URL)
295+ mockGetRemoteUrl . mockReturnValueOnce ( null ) . mockReturnValueOnce ( urlInput . url ) ;
296+
297+ workflow . addFilePart ( 'test.pdf' ) . applyAction ( action ) ;
298+
299+ // Verify the action's fileInput contains the URL
300+ expect ( action . fileInput ) . toEqual ( urlInput ) ;
301+
302+ // Verify only the test.pdf was registered as local asset (not the JSON URL)
303+ expect ( workflow [ 'assets' ] . size ) . toBe ( 1 ) ;
304+ } ) ;
305+
306+ it ( 'should handle URL input for applyXfdf action' , ( ) => {
307+ const urlInput : UrlInput = { type : 'url' , url : 'https://example.com/annotations.xfdf' } ;
308+ const action = BuildActions . applyXfdf ( urlInput ) ;
309+
310+ // Mock getRemoteUrl: first call for test.pdf (returns null), second for URL action (returns URL)
311+ mockGetRemoteUrl . mockReturnValueOnce ( null ) . mockReturnValueOnce ( urlInput . url ) ;
312+
313+ workflow . addFilePart ( 'test.pdf' ) . applyAction ( action ) ;
314+
315+ // Verify the action's fileInput contains the URL
316+ expect ( action . fileInput ) . toEqual ( urlInput ) ;
317+
318+ // Verify only the test.pdf was registered as local asset (not the XFDF URL)
319+ expect ( workflow [ 'assets' ] . size ) . toBe ( 1 ) ;
320+ } ) ;
277321 } ) ;
278322
279323 describe ( 'output methods' , ( ) => {
0 commit comments