mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
initialized postgres support
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { Default, parse, stripMark } from "../../../../src/core/utils";
|
||||
import { Field, type SchemaResponse, TextField, baseFieldConfigSchema } from "../../../../src/data";
|
||||
import { runBaseFieldTests, transformPersist } from "./inc";
|
||||
import { Default, stripMark } from "../../../../src/core/utils";
|
||||
import { baseFieldConfigSchema, Field } from "../../../../src/data/fields/Field";
|
||||
import { runBaseFieldTests } from "./inc";
|
||||
|
||||
describe("[data] Field", async () => {
|
||||
class FieldSpec extends Field {
|
||||
schema(): SchemaResponse {
|
||||
return this.useSchemaHelper("text");
|
||||
}
|
||||
getSchema() {
|
||||
return baseFieldConfigSchema;
|
||||
}
|
||||
}
|
||||
|
||||
test("fieldSpec", () => {
|
||||
expect(new FieldSpec("test").schema()).toEqual({
|
||||
name: "test",
|
||||
type: "text",
|
||||
nullable: true, // always true
|
||||
dflt: undefined, // never using default value
|
||||
});
|
||||
});
|
||||
|
||||
runBaseFieldTests(FieldSpec, { defaultValue: "test", schemaType: "text" });
|
||||
|
||||
test("default config", async () => {
|
||||
const config = Default(baseFieldConfigSchema, {});
|
||||
expect(stripMark(new FieldSpec("test").config)).toEqual(config);
|
||||
expect(stripMark(new FieldSpec("test").config)).toEqual(config as any);
|
||||
});
|
||||
|
||||
test("transformPersist (specific)", async () => {
|
||||
|
||||
@@ -10,7 +10,12 @@ describe("[data] PrimaryField", async () => {
|
||||
|
||||
test("schema", () => {
|
||||
expect(field.name).toBe("primary");
|
||||
expect(field.schema()).toEqual(["primary", "integer", expect.any(Function)]);
|
||||
expect(field.schema()).toEqual({
|
||||
name: "primary",
|
||||
type: "integer" as const,
|
||||
nullable: false,
|
||||
primary: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("hasDefault", async () => {
|
||||
|
||||
@@ -34,11 +34,14 @@ export function runBaseFieldTests(
|
||||
|
||||
test("schema", () => {
|
||||
expect(noConfigField.name).toBe("no_config");
|
||||
expect(noConfigField.schema(null as any)).toEqual([
|
||||
"no_config",
|
||||
config.schemaType,
|
||||
expect.any(Function),
|
||||
]);
|
||||
|
||||
const { type, name, nullable, dflt } = noConfigField.schema()!;
|
||||
expect({ type, name, nullable, dflt }).toEqual({
|
||||
type: config.schemaType as any,
|
||||
name: "no_config",
|
||||
nullable: true, // always true
|
||||
dflt: undefined, // never using default value
|
||||
});
|
||||
});
|
||||
|
||||
test("hasDefault", async () => {
|
||||
|
||||
Reference in New Issue
Block a user