feat: upgrade sentry and use metrics * feat: upgrade sentry and use metrics * remove ununsed deps * rename span * . Approved-by: Linus Flood
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { flattenInput } from "./flattenInput"
|
|
|
|
describe("flattenInput", () => {
|
|
it("should return undefined for null input", () => {
|
|
expect(flattenInput(null)).toBeUndefined()
|
|
})
|
|
|
|
it("should return undefined for non-object input", () => {
|
|
expect(flattenInput("string")).toBeUndefined()
|
|
expect(flattenInput(123)).toBeUndefined()
|
|
expect(flattenInput(true)).toBeUndefined()
|
|
})
|
|
|
|
it("should return undefined for empty object", () => {
|
|
expect(flattenInput({})).toBeUndefined()
|
|
})
|
|
|
|
it("should return undefined for object with no primitive values", () => {
|
|
expect(flattenInput({ nested: { deep: "value" } })).toBeUndefined()
|
|
expect(flattenInput({ arr: [1, 2, 3] })).toBeUndefined()
|
|
expect(flattenInput({ fn: () => {} })).toBeUndefined()
|
|
})
|
|
|
|
it("should flatten object with primitive values", () => {
|
|
const input = {
|
|
name: "test",
|
|
age: 25,
|
|
active: true,
|
|
}
|
|
const result = flattenInput(input)
|
|
expect(result).toEqual({
|
|
"input.name": "test",
|
|
"input.age": 25,
|
|
"input.active": true,
|
|
})
|
|
})
|
|
|
|
it("should filter out non-primitive values and flatten remaining", () => {
|
|
const input = {
|
|
name: "test",
|
|
count: 42,
|
|
nested: { deep: "value" },
|
|
valid: false,
|
|
array: [1, 2, 3],
|
|
}
|
|
const result = flattenInput(input)
|
|
expect(result).toEqual({
|
|
"input.name": "test",
|
|
"input.count": 42,
|
|
"input.valid": false,
|
|
})
|
|
})
|
|
|
|
it("should handle mixed primitive types", () => {
|
|
const input = {
|
|
str: "hello",
|
|
num: 0,
|
|
bool: false,
|
|
negNum: -5,
|
|
}
|
|
const result = flattenInput(input)
|
|
expect(result).toEqual({
|
|
"input.str": "hello",
|
|
"input.num": 0,
|
|
"input.bool": false,
|
|
"input.negNum": -5,
|
|
})
|
|
})
|
|
})
|