Add more test for metadata

This commit is contained in:
Arnaud 2025-05-30 12:58:27 +02:00
parent d3f5d1dea5
commit 0aae4eac0f
No known key found for this signature in database
GPG Key ID: B8FBC178F10CA7AE

View File

@ -38,6 +38,45 @@ describe("data", () => {
assert.ok(treeCid);
});
it("saves the metadata uploads provided during the upload", async () => {
const content = crypto.randomBytes(16).toString("hex");
const strategy = new NodeUploadStategy(content, {
filename: "hello.txt",
mimetype: "text/plain",
});
const res = data.upload(strategy);
const cid = await res.result;
assert.ok(cid.error == false);
assert.ok(cid.data);
const manifest = await data.fetchManifest(cid.data);
assert.ok(manifest.error == false);
assert.strictEqual(manifest.data.cid, cid.data);
const { filename, mimetype } = manifest.data.manifest;
assert.strictEqual(filename, "hello.txt");
assert.ok(mimetype, "text/plain");
});
it("fails when providing wrong metadata", async () => {
const content = crypto.randomBytes(16).toString("hex");
const strategy = new NodeUploadStategy(content, {
filename: "hello.txt",
mimetype: "plain/text",
});
const res = data.upload(strategy);
const cid = await res.result;
assert.ok(cid.error == true);
assert.ok(
cid.data.message.includes(" The MIME type 'plain/text' is not valid")
);
assert.equal(cid.data.code, 422);
});
it("delete a file a locally", async () => {
const content = "b".repeat(131072);
const strategy = new NodeUploadStategy(content);
@ -58,6 +97,24 @@ describe("data", () => {
assert.notOk(cids.data.content.find((c) => c.cid == cid.data));
});
it("doesn't do anything when trying to delete a non existing cid", async () => {
const content = crypto.randomBytes(16).toString("hex");
const strategy = new NodeUploadStategy(content);
const res = spData.upload(strategy);
const cid = await res.result;
assert.ok(cid.error == false);
assert.ok(cid.data);
const del = await data.delete(cid.data);
assert.ok(del.error == false);
});
it("returns an error when providing an invalid cid", async () => {
const del = await data.delete("hello");
assert.ok(del.error);
assert.ok(del.data.message.includes("Incorrect Cid"));
});
it("updates the space available when storing data", async () => {
const content = crypto.randomBytes(16).toString("hex");