websri/test/get-prioritized-hash-algorithm.ts
Kohei Watanabe c026b150f2
Some checks are pending
test / Node.js v20 (push) Waiting to run
test / Node.js v22 (push) Waiting to run
test / Deno (push) Waiting to run
test / Bun (push) Waiting to run
replace tsup with pkgroll and tsx for bundling
2024-10-02 19:07:50 +09:00

27 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { getPrioritizedHashAlgorithm } from "../src/index.ts";
test("return the most collision-resistant hash algorithm", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("sha256", "sha512"), "sha512");
});
test("if the priority is equal, return the empty string", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("sha256", "sha256"), "");
});
test("if both hash algorithms are not supported, return the empty string", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha1"), "");
});
test("if one of the hash algorithms is unsupported, return the supported hash algorithm", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha256"), "sha256");
});
test("if both strings are empty, return the empty string", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("", ""), "");
});
test("if either is the empty string, it return the supported hash algorithm", function () {
assert.strictEqual(getPrioritizedHashAlgorithm("sha256", ""), "sha256");
});