Files
xarticleaudio/test/storage-client-integration.test.js

40 lines
1.1 KiB
JavaScript

"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const { createStorageAdapter } = require("../src/integrations/storage-client");
test("uploadAudio sends put command", async () => {
const sent = [];
const adapter = createStorageAdapter({
bucket: "b1",
client: {
async send(command) {
sent.push(command.input);
},
},
signedUrlFactory: async () => "https://signed.example",
});
const res = await adapter.uploadAudio({
key: "audio/1.mp3",
body: Buffer.from("abc"),
});
assert.equal(res.bucket, "b1");
assert.equal(sent.length, 1);
assert.equal(sent[0].Bucket, "b1");
assert.equal(sent[0].Key, "audio/1.mp3");
});
test("getSignedDownloadUrl uses provided signer", async () => {
const adapter = createStorageAdapter({
bucket: "b1",
client: { async send() {} },
signedUrlFactory: async (_client, command, options) => `signed:${command.input.Key}:${options.expiresIn}`,
});
const url = await adapter.getSignedDownloadUrl("audio/2.mp3", 120);
assert.equal(url, "signed:audio/2.mp3:120");
});