Files
pocketbase-typegen/test/utils.test.ts
Maximilian Skowron 8744267b3e Support PocketBase version 0.23.0-rc12 (#103)
* feat(*): upgrade to schema version 0.23.0 of pocketbase

* test(*): update all snapshots and test-db/schema

* test(Dockerfile): use pocketbase version 0.23.0-rc12 for integration tests

* refactor(constants): remove updated/created fields from baserecords

PocketBase no longer adds those fields by default.

* feat(*): use new _superusers collection for url generation

* refactor(test): remove auxiliary.db

* docs(readme): update target version and add npx command example with version

* test(Dockerfile): upgrade rc version to 0.23.0-rc13

* test(*): fix integration tests to be compatible with 0.23.0-rc14

* refactor(Dockerfile): upgrade to 0.23.1
2024-11-27 20:27:38 +11:00

77 lines
2.4 KiB
TypeScript

import {
getOptionEnumName,
getOptionValues,
getSystemFields,
sanitizeFieldName,
toPascalCase,
} from "../src/utils"
import { FieldSchema } from "../src/types"
describe("toPascalCase", () => {
it("return pascal case string", () => {
expect(toPascalCase("foo bar")).toEqual("FooBar")
expect(toPascalCase("Foo Bar")).toEqual("FooBar")
expect(toPascalCase("fooBar")).toEqual("FooBar")
expect(toPascalCase("FooBar")).toEqual("FooBar")
expect(toPascalCase("--foo-bar--")).toEqual("FooBar")
expect(toPascalCase("__FOO_BAR__")).toEqual("FooBar")
expect(toPascalCase("!--foo-¿?-bar--121-**%")).toEqual("FooBar121")
expect(toPascalCase("Here i am")).toEqual("HereIAm")
expect(toPascalCase("FOO BAR")).toEqual("FooBar")
expect(toPascalCase("ça.roule")).toEqual("ÇaRoule")
expect(toPascalCase("добрий-день")).toEqual("ДобрийДень")
})
})
describe("sanitizeFieldName", () => {
it("returns valid typescript fields", () => {
expect(sanitizeFieldName("foo_bar")).toEqual("foo_bar")
expect(sanitizeFieldName("4number")).toEqual('"4number"')
})
})
describe("getSystemFields", () => {
it("returns the system field type name for a given collection type", () => {
expect(getSystemFields("auth")).toBe("AuthSystemFields")
expect(getSystemFields("base")).toBe("BaseSystemFields")
expect(getSystemFields("view")).toBe("BaseSystemFields")
})
})
describe("getOptionEnumName", () => {
it("returns the enum name for select field options", () => {
expect(getOptionEnumName("orders", "type")).toBe("OrdersTypeOptions")
expect(getOptionEnumName("orders_with_underscore", "type_underscore")).toBe(
"OrdersWithUnderscoreTypeUnderscoreOptions"
)
})
})
describe("getOptionValues", () => {
it("returns empty array when no select field values", () => {
const fieldWithoutValues: FieldSchema = {
id: "1",
name: "myfield",
required: false,
system: false,
type: "text",
unique: false,
}
expect(getOptionValues(fieldWithoutValues)).toEqual([])
})
it("returns deduped select field values", () => {
const fieldWithValues: FieldSchema = {
id: "1",
name: "myfield",
values: ["one", "one", "one", "two"],
required: false,
system: false,
type: "text",
unique: false,
}
expect(getOptionValues(fieldWithValues)).toEqual(["one", "two"])
})
})