A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4 156 lines 5.0 kB view raw
1import { describe, it } from "@std/testing/bdd"; 2import { expect } from "@std/expect"; 3 4import { testWeb } from "@tests/common/index.ts"; 5import type { Track } from "~/definitions/types.d.ts"; 6 7describe("components/input/s3", () => { 8 it("has correct SCHEME property", async () => { 9 const scheme = await testWeb(async () => { 10 const mod = await import("~/components/input/s3/element.js"); 11 const input = new mod.CLASS(); 12 document.body.append(input); 13 return input.SCHEME; 14 }); 15 16 expect(scheme).toBe("s3"); 17 }); 18 19 it("consult returns undetermined for scheme only", async () => { 20 const result = await testWeb(async () => { 21 const mod = await import("~/components/input/s3/element.js"); 22 const input = new mod.CLASS(); 23 document.body.append(input); 24 return await input.consult("s3"); 25 }); 26 27 expect(result.supported).toBe(true); 28 if (result.supported) { 29 expect(result.consult).toBe("undetermined"); 30 } 31 }); 32 33 it("consult returns undetermined for an invalid S3 URI", async () => { 34 const result = await testWeb(async () => { 35 const mod = await import("~/components/input/s3/element.js"); 36 const input = new mod.CLASS(); 37 document.body.append(input); 38 return await input.consult("s3://notvalid"); 39 }); 40 41 expect(result.supported).toBe(true); 42 if (result.supported) { 43 expect(result.consult).toBe("undetermined"); 44 } 45 }); 46 47 it("detach with s3 scheme removes all s3 tracks", async () => { 48 const remaining = await testWeb(async () => { 49 const mod = await import("~/components/input/s3/element.js"); 50 const input = new mod.CLASS(); 51 document.body.append(input); 52 53 const tracks: Track[] = [ 54 { 55 $type: "sh.diffuse.output.track", 56 id: "1", 57 uri: "s3://key:secret@s3.amazonaws.com/music/track1.mp3?bucketName=my-bucket&region=us-east-1", 58 }, 59 { 60 $type: "sh.diffuse.output.track", 61 id: "2", 62 uri: "s3://key:secret@s3.amazonaws.com/music/track2.mp3?bucketName=my-bucket&region=us-east-1", 63 }, 64 ]; 65 66 return await input.detach({ fileUriOrScheme: "s3", tracks }); 67 }); 68 69 expect(remaining.length).toBe(0); 70 }); 71 72 it("detach with non-matching scheme returns all tracks", async () => { 73 const remaining = await testWeb(async () => { 74 const mod = await import("~/components/input/s3/element.js"); 75 const input = new mod.CLASS(); 76 document.body.append(input); 77 78 const tracks: Track[] = [ 79 { 80 $type: "sh.diffuse.output.track", 81 id: "1", 82 uri: "s3://key:secret@s3.amazonaws.com/music/track1.mp3?bucketName=my-bucket&region=us-east-1", 83 }, 84 ]; 85 86 return await input.detach({ fileUriOrScheme: "https", tracks }); 87 }); 88 89 expect(remaining.length).toBe(1); 90 }); 91 92 it("detach with specific bucket URI removes only matching tracks", async () => { 93 const remaining = await testWeb(async () => { 94 const mod = await import("~/components/input/s3/element.js"); 95 const input = new mod.CLASS(); 96 document.body.append(input); 97 98 // bucketId is keyed by accessKey:secretKey@host — use different hosts 99 const tracks: Track[] = [ 100 { 101 $type: "sh.diffuse.output.track", 102 id: "1", 103 uri: "s3://key:secret@s3-host-a.amazonaws.com/track1.mp3?bucketName=bucket-a&region=us-east-1", 104 }, 105 { 106 $type: "sh.diffuse.output.track", 107 id: "2", 108 uri: "s3://key:secret@s3-host-b.amazonaws.com/track2.mp3?bucketName=bucket-b&region=us-east-1", 109 }, 110 ]; 111 112 return await input.detach({ 113 fileUriOrScheme: 114 "s3://key:secret@s3-host-a.amazonaws.com/?bucketName=bucket-a&region=us-east-1", 115 tracks, 116 }); 117 }); 118 119 expect(remaining.length).toBe(1); 120 expect(remaining[0].id).toBe("2"); 121 }); 122 123 it("artwork returns null", async () => { 124 const result = await testWeb(async () => { 125 const mod = await import("~/components/input/s3/element.js"); 126 const input = new mod.CLASS(); 127 document.body.append(input); 128 return await input.artwork( 129 "s3://key:secret@s3.amazonaws.com/music/track1.mp3?bucketName=my-bucket&region=us-east-1", 130 ); 131 }); 132 133 expect(result).toBe(null); 134 }); 135 136 it("sources returns labels with bucket name and host", async () => { 137 const sources = await testWeb(async () => { 138 const mod = await import("~/components/input/s3/element.js"); 139 const input = new mod.CLASS(); 140 document.body.append(input); 141 142 const tracks: Track[] = [ 143 { 144 $type: "sh.diffuse.output.track", 145 id: "1", 146 uri: "s3://key:secret@s3.amazonaws.com/music/track1.mp3?bucketName=my-bucket&region=us-east-1", 147 }, 148 ]; 149 150 return input.sources(tracks); 151 }); 152 153 expect(sources.length).toBe(1); 154 expect(sources[0].label).toContain("my-bucket"); 155 }); 156});