61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { normalizeMachineRemoteAccess } from "@/components/admin/machines/admin-machines-overview"
|
|
|
|
describe("normalizeMachineRemoteAccess", () => {
|
|
it("returns null when value is empty", () => {
|
|
expect(normalizeMachineRemoteAccess(undefined)).toBeNull()
|
|
expect(normalizeMachineRemoteAccess(" ")).toBeNull()
|
|
})
|
|
|
|
it("parses plain identifier strings", () => {
|
|
const result = normalizeMachineRemoteAccess("PC-001")
|
|
expect(result).toEqual({
|
|
provider: null,
|
|
identifier: "PC-001",
|
|
url: null,
|
|
notes: null,
|
|
lastVerifiedAt: null,
|
|
metadata: null,
|
|
})
|
|
})
|
|
|
|
it("detects URLs in string input", () => {
|
|
const result = normalizeMachineRemoteAccess("https://remote.example.com/session/123")
|
|
expect(result).toEqual({
|
|
provider: null,
|
|
identifier: null,
|
|
url: "https://remote.example.com/session/123",
|
|
notes: null,
|
|
lastVerifiedAt: null,
|
|
metadata: null,
|
|
})
|
|
})
|
|
|
|
it("normalizes object payload with aliases", () => {
|
|
const timestamp = 1_701_234_567_890
|
|
const result = normalizeMachineRemoteAccess({
|
|
provider: "AnyDesk",
|
|
code: "123-456-789",
|
|
remoteUrl: "https://anydesk.com/session/123",
|
|
note: "Suporte avançado",
|
|
verifiedAt: timestamp,
|
|
extraTag: "vip",
|
|
})
|
|
expect(result).toEqual({
|
|
provider: "AnyDesk",
|
|
identifier: "123-456-789",
|
|
url: "https://anydesk.com/session/123",
|
|
notes: "Suporte avançado",
|
|
lastVerifiedAt: timestamp,
|
|
metadata: {
|
|
provider: "AnyDesk",
|
|
code: "123-456-789",
|
|
remoteUrl: "https://anydesk.com/session/123",
|
|
note: "Suporte avançado",
|
|
verifiedAt: timestamp,
|
|
extraTag: "vip",
|
|
},
|
|
})
|
|
})
|
|
})
|