websri/test/create-integrity-metadata.ts

24 lines
825 B
TypeScript
Raw Normal View History

2024-09-17 19:08:56 +09:00
import assert from "node:assert";
import { test } from "node:test";
import { createIntegrityMetadata, IntegrityMetadata } from "../src/index.ts";
2024-09-17 19:08:56 +09:00
test("instantiate a new IntegrityMetadata", async function () {
const res = new Response("Hello, world!");
const data = await res.arrayBuffer();
const integrityMetadata = await createIntegrityMetadata("sha256", data);
assert(integrityMetadata instanceof IntegrityMetadata);
});
test("instantiate with the specified hash algorithm and ArrayBuffer", async function () {
const res = new Response("Hello, world!");
const data = await res.arrayBuffer();
const integrityMetadata = await createIntegrityMetadata("sha256", data);
assert.deepEqual(integrityMetadata, {
alg: "sha256",
val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
opt: [],
});
});