@@ -55,9 +55,24 @@ describe('Map Shares and Downloads', () => {
5555
5656 it ( 'should list all map shares' , async ( t ) => {
5757 const { sender, createShare } = await startServers ( t )
58- const share = await createShare ( ) . json ( )
59- const shares = await sender . get ( 'mapShares' ) . json ( )
60- expect ( shares ) . toEqual ( [ share ] )
58+
59+ // Test with zero shares
60+ const emptyShares = await sender . get ( 'mapShares' ) . json ( )
61+ expect ( emptyShares ) . toEqual ( [ ] )
62+
63+ // Test with one share
64+ const share1 = await createShare ( ) . json ( )
65+ const oneShare = await sender . get ( 'mapShares' ) . json ( )
66+ expect ( oneShare ) . toEqual ( [ share1 ] )
67+
68+ // Test with multiple shares
69+ const share2 = await createShare ( ) . json ( )
70+ const share3 = await createShare ( ) . json ( )
71+ const multipleShares = await sender . get ( 'mapShares' ) . json < any [ ] > ( )
72+ expect ( multipleShares ) . toHaveLength ( 3 )
73+ expect ( multipleShares . map ( ( s ) => s . shareId ) ) . toContain ( share1 . shareId )
74+ expect ( multipleShares . map ( ( s ) => s . shareId ) ) . toContain ( share2 . shareId )
75+ expect ( multipleShares . map ( ( s ) => s . shareId ) ) . toContain ( share3 . shareId )
6176 } )
6277
6378 it ( 'should get a specific map share' , async ( t ) => {
@@ -129,6 +144,41 @@ describe('Map Shares and Downloads', () => {
129144 expect ( shares . map ( ( s : any ) => s . shareId ) ) . toContain ( share1 . shareId )
130145 expect ( shares . map ( ( s : any ) => s . shareId ) ) . toContain ( share2 . shareId )
131146 } )
147+
148+ it ( 'should allow creating shares for multiple receivers' , async ( t ) => {
149+ const { sender, receiver, createShare } = await startServers ( t )
150+
151+ // Create a third device (another receiver)
152+ const receiver2KeyPair = SecretStreamAgent . keyPair ( Buffer . alloc ( 32 , 2 ) )
153+ const receiver2DeviceId = z32 . encode ( receiver2KeyPair . publicKey )
154+
155+ // Create share for first receiver
156+ const share1 = await createShare ( ) . json ( )
157+ expect ( share1 ) . toHaveProperty ( 'shareId' )
158+ expect ( share1 . receiverDeviceId ) . toBe ( receiver . deviceId )
159+
160+ // Create share for second receiver
161+ const response2 = await sender . post ( 'mapShares' , {
162+ json : {
163+ mapId : 'custom' ,
164+ receiverDeviceId : receiver2DeviceId ,
165+ } ,
166+ } )
167+ expect ( response2 . status ) . toBe ( 201 )
168+ const share2 = await response2 . json < any > ( )
169+ expect ( share2 ) . toHaveProperty ( 'shareId' )
170+ expect ( share2 . receiverDeviceId ) . toBe ( receiver2DeviceId )
171+
172+ // Shares should have different IDs and different receivers
173+ expect ( share1 . shareId ) . not . toBe ( share2 . shareId )
174+ expect ( share1 . receiverDeviceId ) . not . toBe ( share2 . receiverDeviceId )
175+
176+ // Both shares should be listed
177+ const shares = await sender . get ( 'mapShares' ) . json < any [ ] > ( )
178+ expect ( shares ) . toHaveLength ( 2 )
179+ expect ( shares . map ( ( s : any ) => s . shareId ) ) . toContain ( share1 . shareId )
180+ expect ( shares . map ( ( s : any ) => s . shareId ) ) . toContain ( share2 . shareId )
181+ } )
132182 } )
133183
134184 describe ( 'Downloads' , ( ) => {
@@ -191,14 +241,44 @@ describe('Map Shares and Downloads', () => {
191241
192242 it ( 'should list all downloads' , async ( t ) => {
193243 const { receiver, createShare, createDownload } = await startServers ( t )
194- const share = await createShare ( ) . json ( )
195244
196- // Now create a download on the receiver using the real share
197- const download = await createDownload ( share ) . json < any > ( )
198- const downloads = await receiver . get ( `downloads` ) . json ( )
199- expect ( downloads ) . toEqual ( [ download ] )
200- // Wait for download to complete to clean up background connections
201- await eventsUntil ( receiver , download . downloadId , 'completed' )
245+ // Test with zero downloads
246+ const emptyDownloads = await receiver . get ( `downloads` ) . json ( )
247+ expect ( emptyDownloads ) . toEqual ( [ ] )
248+
249+ // Test with one download
250+ const share1 = await createShare ( ) . json ( )
251+ const download1 = await createDownload ( share1 ) . json < any > ( )
252+ const oneDownload = await receiver . get ( `downloads` ) . json ( )
253+ expect ( oneDownload ) . toEqual ( [ download1 ] )
254+
255+ // Wait for first download to complete before starting second
256+ await eventsUntil ( receiver , download1 . downloadId , 'completed' )
257+
258+ // Test with multiple downloads
259+ const share2 = await createShare ( ) . json ( )
260+ const download2 = await createDownload ( share2 ) . json < any > ( )
261+
262+ const share3 = await createShare ( ) . json ( )
263+ const download3 = await createDownload ( share3 ) . json < any > ( )
264+
265+ const multipleDownloads = await receiver . get ( `downloads` ) . json < any [ ] > ( )
266+ expect ( multipleDownloads ) . toHaveLength ( 3 )
267+ expect ( multipleDownloads . map ( ( d ) => d . downloadId ) ) . toContain (
268+ download1 . downloadId ,
269+ )
270+ expect ( multipleDownloads . map ( ( d ) => d . downloadId ) ) . toContain (
271+ download2 . downloadId ,
272+ )
273+ expect ( multipleDownloads . map ( ( d ) => d . downloadId ) ) . toContain (
274+ download3 . downloadId ,
275+ )
276+
277+ // Wait for remaining downloads to complete to clean up background connections
278+ await Promise . all ( [
279+ eventsUntil ( receiver , download2 . downloadId , 'completed' ) ,
280+ eventsUntil ( receiver , download3 . downloadId , 'completed' ) ,
281+ ] )
202282 } )
203283
204284 it ( 'should get a specific download' , async ( t ) => {
0 commit comments