mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: Add the rest of the config builder test
This commit is contained in:
@@ -158,3 +158,47 @@ describe("values", () => {
|
|||||||
testOutput<typeof validator._TYPE, number[]>()(null);
|
testOutput<typeof validator._TYPE, number[]>()(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Builder List", () => {
|
||||||
|
test("obj", () => {
|
||||||
|
const value = Value.list(
|
||||||
|
List.obj(
|
||||||
|
{
|
||||||
|
name: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
spec: Config.of({ test: Value.boolean({ name: "test" }) }),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const validator = value.validator();
|
||||||
|
validator.unsafeCast([{ test: true }]);
|
||||||
|
testOutput<typeof validator._TYPE, { test: boolean }[]>()(null);
|
||||||
|
});
|
||||||
|
test("string", () => {
|
||||||
|
const value = Value.list(
|
||||||
|
List.string(
|
||||||
|
{
|
||||||
|
name: "test",
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const validator = value.validator();
|
||||||
|
validator.unsafeCast(["test", "text"]);
|
||||||
|
testOutput<typeof validator._TYPE, string[]>()(null);
|
||||||
|
});
|
||||||
|
test("number", () => {
|
||||||
|
const value = Value.list(
|
||||||
|
List.number(
|
||||||
|
{
|
||||||
|
name: "test",
|
||||||
|
},
|
||||||
|
{ integral: true }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const validator = value.validator();
|
||||||
|
validator.unsafeCast([12, 45]);
|
||||||
|
testOutput<typeof validator._TYPE, number[]>()(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import { BuilderExtract, IBuilder } from "./builder";
|
import { BuilderExtract, IBuilder } from "./builder";
|
||||||
import { Config } from "./config";
|
import { Config } from "./config";
|
||||||
import {
|
import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types";
|
||||||
InputSpec,
|
|
||||||
ListValueSpecNumber,
|
|
||||||
ListValueSpecString,
|
|
||||||
UniqueBy,
|
|
||||||
ValueSpecList,
|
|
||||||
} from "../config-types";
|
|
||||||
import { guardAll } from "../../util";
|
import { guardAll } from "../../util";
|
||||||
/**
|
/**
|
||||||
* Used as a subtype of Value.list
|
* Used as a subtype of Value.list
|
||||||
@@ -102,7 +96,8 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
name: string;
|
name: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
warning?: string | null;
|
warning?: string | null;
|
||||||
default: Record<string, unknown>[];
|
/** Default [] */
|
||||||
|
default?: Record<string, unknown>[];
|
||||||
/** Default = "(\*,\*)" */
|
/** Default = "(\*,\*)" */
|
||||||
range?: string;
|
range?: string;
|
||||||
},
|
},
|
||||||
@@ -123,6 +118,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
|||||||
};
|
};
|
||||||
const value = {
|
const value = {
|
||||||
spec,
|
spec,
|
||||||
|
default: [],
|
||||||
...a,
|
...a,
|
||||||
};
|
};
|
||||||
return new List({
|
return new List({
|
||||||
|
|||||||
Reference in New Issue
Block a user