mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
added format command and added trailing commas to reduce conflicts
This commit is contained in:
@@ -10,12 +10,12 @@ describe("[data] EnumField", async () => {
|
||||
runBaseFieldTests(
|
||||
EnumField,
|
||||
{ defaultValue: "a", schemaType: "text" },
|
||||
{ options: options(["a", "b", "c"]) }
|
||||
{ options: options(["a", "b", "c"]) },
|
||||
);
|
||||
|
||||
test("yields if default value is not a valid option", async () => {
|
||||
expect(
|
||||
() => new EnumField("test", { options: options(["a", "b"]), default_value: "c" })
|
||||
() => new EnumField("test", { options: options(["a", "b"]), default_value: "c" }),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ describe("[data] EnumField", async () => {
|
||||
const field = new EnumField("test", {
|
||||
options: options(["a", "b", "c"]),
|
||||
default_value: "a",
|
||||
required: true
|
||||
required: true,
|
||||
});
|
||||
|
||||
expect(field.transformRetrieve(null)).toBe("a");
|
||||
|
||||
@@ -24,20 +24,20 @@ describe("[data] Field", async () => {
|
||||
const required = new FieldSpec("test", { required: true });
|
||||
const requiredDefault = new FieldSpec("test", {
|
||||
required: true,
|
||||
default_value: "test"
|
||||
default_value: "test",
|
||||
});
|
||||
|
||||
expect(required.transformPersist(null, undefined as any, undefined as any)).rejects.toThrow();
|
||||
expect(
|
||||
required.transformPersist(undefined, undefined as any, undefined as any)
|
||||
required.transformPersist(undefined, undefined as any, undefined as any),
|
||||
).rejects.toThrow();
|
||||
|
||||
// works because it has a default value
|
||||
expect(
|
||||
requiredDefault.transformPersist(null, undefined as any, undefined as any)
|
||||
requiredDefault.transformPersist(null, undefined as any, undefined as any),
|
||||
).resolves.toBeDefined();
|
||||
expect(
|
||||
requiredDefault.transformPersist(undefined, undefined as any, undefined as any)
|
||||
requiredDefault.transformPersist(undefined, undefined as any, undefined as any),
|
||||
).resolves.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
EntityIndex,
|
||||
type EntityManager,
|
||||
Field,
|
||||
type SchemaResponse
|
||||
type SchemaResponse,
|
||||
} from "../../../../src/data";
|
||||
|
||||
class TestField extends Field {
|
||||
|
||||
@@ -7,7 +7,7 @@ describe("[data] JsonField", async () => {
|
||||
runBaseFieldTests(JsonField, {
|
||||
defaultValue: { a: 1 },
|
||||
sampleValues: ["string", { test: 1 }, 1],
|
||||
schemaType: "text"
|
||||
schemaType: "text",
|
||||
});
|
||||
|
||||
test("transformPersist (no config)", async () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ export function transformPersist(field: Field, value: any, context?: TActionCont
|
||||
export function runBaseFieldTests(
|
||||
fieldClass: ConstructableField,
|
||||
config: FieldTestConfig,
|
||||
_requiredConfig: any = {}
|
||||
_requiredConfig: any = {},
|
||||
) {
|
||||
const noConfigField = new fieldClass("no_config", _requiredConfig);
|
||||
const fillable = new fieldClass("fillable", { ..._requiredConfig, fillable: true });
|
||||
@@ -29,7 +29,7 @@ export function runBaseFieldTests(
|
||||
..._requiredConfig,
|
||||
fillable: true,
|
||||
required: true,
|
||||
default_value: config.defaultValue
|
||||
default_value: config.defaultValue,
|
||||
});
|
||||
|
||||
test("schema", () => {
|
||||
@@ -37,7 +37,7 @@ export function runBaseFieldTests(
|
||||
expect(noConfigField.schema(null as any)).toEqual([
|
||||
"no_config",
|
||||
config.schemaType,
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ export function runBaseFieldTests(
|
||||
//order: 1,
|
||||
fillable: true,
|
||||
required: false,
|
||||
hidden: false
|
||||
hidden: false,
|
||||
//virtual: false,
|
||||
//default_value: undefined
|
||||
};
|
||||
@@ -105,20 +105,20 @@ export function runBaseFieldTests(
|
||||
const json = field.toJSON();
|
||||
return {
|
||||
...json,
|
||||
config: omit(json.config, ["html"])
|
||||
config: omit(json.config, ["html"]),
|
||||
};
|
||||
}
|
||||
|
||||
expect(fieldJson(noConfigField)).toEqual({
|
||||
//name: "no_config",
|
||||
type: noConfigField.type,
|
||||
config: _config
|
||||
config: _config,
|
||||
});
|
||||
|
||||
expect(fieldJson(fillable)).toEqual({
|
||||
//name: "fillable",
|
||||
type: noConfigField.type,
|
||||
config: _config
|
||||
config: _config,
|
||||
});
|
||||
|
||||
expect(fieldJson(required)).toEqual({
|
||||
@@ -126,8 +126,8 @@ export function runBaseFieldTests(
|
||||
type: required.type,
|
||||
config: {
|
||||
..._config,
|
||||
required: true
|
||||
}
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(fieldJson(hidden)).toEqual({
|
||||
@@ -135,8 +135,8 @@ export function runBaseFieldTests(
|
||||
type: required.type,
|
||||
config: {
|
||||
..._config,
|
||||
hidden: true
|
||||
}
|
||||
hidden: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(fieldJson(dflt)).toEqual({
|
||||
@@ -144,8 +144,8 @@ export function runBaseFieldTests(
|
||||
type: dflt.type,
|
||||
config: {
|
||||
..._config,
|
||||
default_value: config.defaultValue
|
||||
}
|
||||
default_value: config.defaultValue,
|
||||
},
|
||||
});
|
||||
|
||||
expect(fieldJson(requiredAndDefault)).toEqual({
|
||||
@@ -155,8 +155,8 @@ export function runBaseFieldTests(
|
||||
..._config,
|
||||
fillable: true,
|
||||
required: true,
|
||||
default_value: config.defaultValue
|
||||
}
|
||||
default_value: config.defaultValue,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user