mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
test(ai): add unit tests for authUtils, decryptionSchemeCache, videoPayloadBuilder (agent)
Added focused unit tests for three core modules to improve coverage: - `js/services/authUtils.js`: Tested `normalizeProviderId` and `normalizeAuthType`. - `js/nostr/decryptionSchemeCache.js`: Tested caching logic, TTL expiration, and cache clearing. - `js/nostr/videoPayloadBuilder.js`: Tested payload extraction and event preparation, including NIP-71 metadata handling. Tests use `node:test` and `node:assert/strict` and are integrated into the existing test suite. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
2ca348bdac
commit
ab72036a4f
3 files changed
+268
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { normalizeProviderId, normalizeAuthType } from "../../js/services/authUtils.js";
|
||||
|
||||
test("authUtils", async (t) => {
|
||||
await t.test("normalizeProviderId", async (t) => {
|
||||
await t.test("returns trimmed string if valid", () => {
|
||||
assert.equal(normalizeProviderId(" provider123 "), "provider123");
|
||||
});
|
||||
|
||||
await t.test("returns 'nip07' fallback if empty", () => {
|
||||
assert.equal(normalizeProviderId(""), "nip07");
|
||||
});
|
||||
|
||||
await t.test("returns 'nip07' fallback if null", () => {
|
||||
assert.equal(normalizeProviderId(null), "nip07");
|
||||
});
|
||||
|
||||
await t.test("returns 'nip07' fallback if undefined", () => {
|
||||
assert.equal(normalizeProviderId(undefined), "nip07");
|
||||
});
|
||||
|
||||
await t.test("returns 'nip07' fallback if not a string", () => {
|
||||
assert.equal(normalizeProviderId(123), "nip07");
|
||||
});
|
||||
});
|
||||
|
||||
await t.test("normalizeAuthType", async (t) => {
|
||||
await t.test("prioritizes authTypeCandidate", () => {
|
||||
assert.equal(normalizeAuthType("candidateType", "fallbackProvider", {}), "candidateType");
|
||||
});
|
||||
|
||||
await t.test("falls back to providerResult.authType", () => {
|
||||
assert.equal(normalizeAuthType(null, "fallbackProvider", { authType: "resultAuthType" }), "resultAuthType");
|
||||
});
|
||||
|
||||
await t.test("falls back to providerResult.providerId", () => {
|
||||
assert.equal(normalizeAuthType(null, "fallbackProvider", { providerId: "resultProviderId" }), "resultProviderId");
|
||||
});
|
||||
|
||||
await t.test("falls back to providerId", () => {
|
||||
assert.equal(normalizeAuthType(null, "fallbackProvider", {}), "fallbackProvider");
|
||||
});
|
||||
|
||||
await t.test("returns 'nip07' if all else fails", () => {
|
||||
assert.equal(normalizeAuthType(null, null, {}), "nip07");
|
||||
});
|
||||
|
||||
await t.test("trims whitespace from results", () => {
|
||||
assert.equal(normalizeAuthType(" candidateType ", "fallbackProvider", {}), "candidateType");
|
||||
});
|
||||
|
||||
await t.test("ignores empty strings in candidates", () => {
|
||||
// Should skip empty candidate and use providerResult
|
||||
assert.equal(normalizeAuthType("", "fallbackProvider", { authType: "resultAuthType" }), "resultAuthType");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user