47 lines
1.3 KiB
JavaScript
47 lines
1.3 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 putObject(bucket, key, body, size, metadata) {
|
|
sent.push({ bucket, key, body, size, metadata });
|
|
},
|
|
async presignedGetObject() {},
|
|
},
|
|
});
|
|
|
|
const payload = Buffer.from("abc");
|
|
const res = await adapter.uploadAudio({
|
|
key: "audio/1.mp3",
|
|
body: payload,
|
|
});
|
|
|
|
assert.equal(res.bucket, "b1");
|
|
assert.equal(sent.length, 1);
|
|
assert.equal(sent[0].bucket, "b1");
|
|
assert.equal(sent[0].key, "audio/1.mp3");
|
|
assert.equal(sent[0].size, payload.length);
|
|
assert.equal(sent[0].metadata["Content-Type"], "audio/mpeg");
|
|
});
|
|
|
|
test("getSignedDownloadUrl uses minio presigner with ttl", async () => {
|
|
const adapter = createStorageAdapter({
|
|
bucket: "b1",
|
|
client: {
|
|
async putObject() {},
|
|
async presignedGetObject(bucket, key, expiresIn) {
|
|
return `signed:${bucket}:${key}:${expiresIn}`;
|
|
},
|
|
},
|
|
});
|
|
|
|
const url = await adapter.getSignedDownloadUrl("audio/2.mp3", 120);
|
|
assert.equal(url, "signed:b1:audio/2.mp3:120");
|
|
});
|