2024-09-17 19:08:56 +09:00
|
|
|
import assert from "node:assert/strict";
|
|
|
|
import { test } from "node:test";
|
2024-10-02 18:50:34 +09:00
|
|
|
import { getPrioritizedHashAlgorithm } from "../src/index.ts";
|
2024-09-17 19:08:56 +09:00
|
|
|
|
|
|
|
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 () {
|
2024-10-02 18:50:34 +09:00
|
|
|
// @ts-expect-error unsupported hash algorithms
|
2024-09-17 19:08:56 +09:00
|
|
|
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha1"), "");
|
|
|
|
});
|
|
|
|
|
2024-09-18 14:21:27 +09:00
|
|
|
test("if one of the hash algorithms is unsupported, return the supported hash algorithm", function () {
|
2024-10-02 18:50:34 +09:00
|
|
|
// @ts-expect-error unsupported hash algorithms
|
2024-09-18 14:21:27 +09:00
|
|
|
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha256"), "sha256");
|
|
|
|
});
|
2024-09-17 19:08:56 +09:00
|
|
|
|
|
|
|
test("if both strings are empty, return the empty string", function () {
|
2024-10-02 18:50:34 +09:00
|
|
|
// @ts-expect-error empty string
|
2024-09-17 19:08:56 +09:00
|
|
|
assert.strictEqual(getPrioritizedHashAlgorithm("", ""), "");
|
|
|
|
});
|
|
|
|
|
2024-10-02 17:23:41 +09:00
|
|
|
test("if either is the empty string, it return the supported hash algorithm", function () {
|
2024-10-02 18:50:34 +09:00
|
|
|
// @ts-expect-error empty string
|
2024-09-18 14:21:27 +09:00
|
|
|
assert.strictEqual(getPrioritizedHashAlgorithm("sha256", ""), "sha256");
|
|
|
|
});
|