feat(ui): add support for showing existing tag options

This commit is contained in:
Aarnav Tale
2026-06-17 11:35:38 -04:00
parent c8b1a30f34
commit 57c8046f99
6 changed files with 190 additions and 9 deletions
+49 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import { isNoExpiry } from "~/utils/node-info";
import { extractTagOwnerTags, isNoExpiry, sortAssignableTags } from "~/utils/node-info";
describe("isNoExpiry", () => {
test("returns true for null", () => {
@@ -27,3 +27,51 @@ describe("isNoExpiry", () => {
expect(isNoExpiry("2020-01-01T00:00:00Z")).toBe(false);
});
});
describe("extractTagOwnerTags", () => {
test("reads tags from HuJSON tagOwners", () => {
expect(
extractTagOwnerTags(`{
// comment
"tagOwners": {
"tag:prod": ["group:admins"],
"tag:server": [],
},
}`),
).toEqual(["tag:prod", "tag:server"]);
});
test("ignores invalid policies", () => {
expect(extractTagOwnerTags("not-json")).toEqual([]);
});
});
describe("sortAssignableTags", () => {
test("unions assigned node tags with ACL tag owners", () => {
expect(
sortAssignableTags(
[
{
id: "1",
givenName: "node",
name: "node",
machineKey: "mkey:test",
nodeKey: "nodekey:test",
discoKey: "discokey:test",
ipAddresses: [],
tags: ["tag:used"],
lastSeen: "",
expiry: null,
online: true,
registerMethod: "REGISTER_METHOD_AUTH_KEY",
createdAt: "",
availableRoutes: [],
approvedRoutes: [],
subnetRoutes: [],
},
],
'{"tagOwners":{"tag:declared":[]}}',
),
).toEqual(["tag:declared", "tag:used"]);
});
});